我想将日志文件从多个位置移动到另一个文件夹,当前日期位于同一位置,源路径来自文本文件。并且源路径包含由于发生错误而导致的空间。
以下是剧本:
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.
按任意键继续。 。
需要帮助..请...
答案 0 :(得分:1)
尝试短路径(文件的短路径不包含空格):
for /f "tokens=*" %%i in (C:\Users\kyckeams\Desktop\Batch\source.txt) do (
set "location=%%~dpsfni"
call :Move
)
echo %location%
答案 1 :(得分:1)
Forfiles使用0x22
双引号
(十六进制22是Ascii 34并且是双引号字符)
所以这会引用这些术语:
编辑: echo 添加到下面 - 查看forfiles命令中此段回显的内容。
"cmd /c echo move 0x22%location%*.*0x22 0x22%location%%curr_date%0x22"
另请注意,您的日志文件在移动命令中的“kenya”之后显示了一个已添加的空格,但它不是两个术语,并且不在粘贴的代码中。