我想將日誌文件從多個位置移動到另一個文件夾,並且當前日期位於同一位置,並且源文件路徑取自文本文件。源路徑包含由於發生錯誤而導致的空間。如何在forfiles中包含空格
下面是腳本:
ECHO ON
set curr_date=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
for /f "tokens=*" %%i in (C:\Users\kyckeams\Desktop\Batch\source.txt) do (
set "location=%%i"
call :Move
)
goto:EOF
:Move
cd %location%
cd /D %location%
mkdir %curr_date%
forfiles /p %location% /m *.log /d -2 /c "cmd /c move %location%*.* %location%%curr_date%"
PAUSE
和錯誤即時得到的是:
C:\Users\kyckeams\Desktop\Batch>ECHO ON
C:\Users\kyckeams\Desktop\Batch>set curr_date=20131102
C:\Users\kyckeams\Desktop\Batch>for /F "tokens=*" %i in (C:\Users\kyckeams\Desktop\Batch\source.txt) do (set "location=%i" call :Move)
C:\Users\kyckeams\Desktop\Batch>(set "location=D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya\Log Files\" call :Move)
C:\Users\kyckeams\Desktop\Batch>cd D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya\Log Files\
C:\Users\kyckeams\Desktop\Batch>cd /D D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya\Log Files\
D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya\Log Files>mkdir 20131102
D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya\Log Files>forfiles /p D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya\Log Files\ /m *.log /d -2 /c "cmd /c move D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya \Log Files\*.* D:\kycintg\KenyaSpecificServices\Unidoc_DML_Executor_Kenya\Log Files\20131102"
ERROR: Invalid argument/option - 'Files\'. Type "FORFILES /?" for usage.
按任意鍵繼續。 。 。
幫助需要..請...
現在,林能夠移動文件到目的地,但即時得到這個誤差作爲下面提到: d:\ kycintg \ KenyaSpecificServices \ UNIDOC〜1 \ LOGFIL〜1> FORFILES/P d:\ kycintg \ KenyaSpecificServices \ UNIDOC 〜1 \ LOGFIL〜1 \/m * .log/d -2/c「cmd/c move D:\ kycintg \ KenyaSpecificServices \ UNIDOC〜1 \ LOGFIL〜1 \ *。* D:\ kycintg \ KenyaSpecificServices \ UNIDOC〜 1個\ LOGFIL〜1 \ 20131102" d:\ kycintg \ KenyaSpecificServices \ UNIDOC〜1 \ LOGFIL〜1 \ KYCEMAUnbarring_3.log d:\ kycintg \ KenyaSpecificServices \ UNIDOC〜1 \ LOGFIL〜1 \ UNIDOC_OFFLINEDBLOG.log 2文件(s)移動。 文件名,目錄名稱或卷標語法不正確。 – user2947599
如果在源位置有多個文件,那麼我得到這個錯誤..文件名,目錄名稱或卷標語法不正確。 – user2947599