2

我想将日志文件从多个位置移动到当前日期在同一位置的另一个文件夹,源路径取自文本文件。并且源路径包含导致错误发生的空格。

下面是脚本:

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.

按任意键继续 。. .


需要帮助..请...

4

2 回答 2

1

尝试使用短路径(文件的短路径不包含空格):

for /f "tokens=*" %%i in (C:\Users\kyckeams\Desktop\Batch\source.txt) do (
set "location=%%~dpsfni"
call :Move
)
echo %location%
于 2013-11-02T12:54:26.330 回答
1

Forfiles 使用0x22双引号的位置
(十六进制 22 是 Ascii 34 并且是双引号字符)

所以这将引用条款:

编辑:下面添加了回声-查看该段在 forfiles 命令中回显的内容。

"cmd /c echo move 0x22%location%*.*0x22 0x22%location%%curr_date%0x22"

另请注意,您的日志文件在 move 命令中的“kenya”之后显示了一个添加的空格,但它不是两个术语,也不是粘贴的代码中。

于 2013-11-02T13:02:46.543 回答