在這裏找到了同樣的問題..我想使用代碼,但我的數據。我絕不是程序員..然而,我可以採取幾乎任何代碼,並使其適用於我。批處理文件找到文件夾中的最新文件,然後複製並重命名爲另一個文件夾
How to code a batch file to copy and rename the most recently dated file?
這裏是我的
@echo on
setLocal DisableDelayedExpansion
pushd N:\
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%G in ('dir/b/od') do (set newest=%%G)
copy %newest% G:\Server_Files\AMI_DATA\TEXT_FILES\NewFile.csv
PAUSE
POPD
而結果...
C:\Documents and Settings\belcherj\Desktop\AMI_BATCH>setLocal DisableDelayedExpa
nsion
C:\Documents and Settings\belcherj\Desktop\AMI_BATCH>pushd N:\
N:\>setLocal EnableDelayedExpansion
N:\>for /F "tokens=* delims= " %G in ('dir/b/od') do (set newest=%G)
N:\>(set newest=System Blink Count__2012-06-27 01_00_46.csv)
N:\>(set newest=System Blink Count__2012-06-28 01_00_32.csv)
N:\>(set newest=System Blink Count__2012-06-29 01_00_33.csv)
N:\>(set newest=System Blink Count__2012-06-30 01_00_42.csv)
N:\>(set newest=System Blink Count__2012-07-01 01_00_32.csv)
N:\>(set newest=System Blink Count__2012-07-02 01_00_31.csv)
N:\>(set newest=System Blink Count__2012-07-03 01_00_29.csv)
N:\>(set newest=System Blink Count__2012-07-04 01_00_39.csv)
N:\>(set newest=System Blink Count__2012-07-05 01_00_34.csv)
N:\>(set newest=System Blink Count__2012-07-06 01_00_31.csv)
N:\>(set newest=System Blink Count__2012-07-07 01_00_32.csv)
N:\>(set newest=System Blink Count__2012-07-08 01_00_30.csv)
N:\>(set newest=System Blink Count__2012-07-09 01_00_40.csv)
N:\>(set newest=System Blink Count__2012-07-10 01_00_29.csv)
N:\>(set newest=System Blink Count__2012-07-11 01_00_44.csv)
N:\>(set newest=System Blink Count__2012-07-12 01_00_34.csv)
N:\>copy System Blink Count__2012-07-12 01_00_34.csv G:\Server_Files\AMI_DATA\TE
XT_FILES\NewFile.csv
The system cannot find the file specified.
N:\>PAUSE
Press any key to continue . . .
我認爲這是與在文件名中的空格..我嘗試了一些我發現的代碼,它給出了相同的結果。我接近只需要一點點推動。 感謝您的時間和幫助。
訣竅!看起來像光盤讓它打開映射的網絡驅動器是什麼讓它的工作..我可能是錯誤的:) ..感謝您的幫助@ dbnham和巴厘島C – jestexman 2012-07-13 16:00:21