传递变量与FORFILES命令 [英] passing variables with forfiles command

查看:300
本文介绍了传递变量与FORFILES命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索就在这里一段时间,但无法找到有效的解决方案。

I've searched on here for a while but can't find a solution that works.

我试图运行下面的(test.bat的):

I'm attempting to run the following (test.bat):

SET CURRENT_DATE=%date:~6,4%_%date:~3,2%_%date:~0,2%
SET DOCSRC = "C:\scripts\e2Vault\docdata"
SET DOCSTAGING = "C:\Scripts\e2Vault\staging"
SET LOGFILE = "C:\Scripts\e2Vault\log files"
SET DOCPROCESS = "C:\scripts\e2Vault\process"
SET DOCREMOVED = "C:\scripts\e2Vault\removed"

forfiles /p "%DOCSRC%" /m *.drd /d -547 /c "cmd /c echo @path && Move @file "%DOCSTAGING%"" >> %LOGFILE%\e2Vault_archive_%CURRENT_DATE%.log

但它给我下面的输出,而无需移动文件或记录:

But it's giving me the following output without moving the files or logging:

C:\scripts\e2Vault>forfiles /p "" /m *.drd /d -547 /c "cmd /c echo @path && Move @file """  1>>\e2Vault_archive_2012_06_19.log
ERROR: Value for '/p' option cannot be empty.
Type "FORFILES /?" for usage.

我一直在使用,尝试和\\在各种配置,但每一个我尽量只显示引号,其中变量应该的。

I have tried using """ and \" in various configurations but every one I try just displays the quotes where the variable should be.

正如你很可能会看到我测试这一点,但变量直播系统路径中有空格的,所以我需要得到它的工作。

As you can probably see I'm testing this but the live system paths for variables have spaces in them so I need to get it working.

如果我不使用SET变量放在绝对路径的脚本工作。

If I do not use the SET variables and put in the absolute paths the script works.

真希望有人能指出我在做什么错!

Really hoping someone can point out what I'm doing wrong!

推荐答案

您不能围绕 = 空格设置命令。要创建环境变量与有空间的结束。

You cannot have spaces around the = in set commands. You're creating environment variables the end with a space there.

SET CURRENT_DATE=%date:~6,4%_%date:~3,2%_%date:~0,2%
SET DOCSRC=C:\scripts\e2Vault\docdata
SET DOCSTAGING=C:\Scripts\e2Vault\staging
SET LOGFILE=C:\Scripts\e2Vault\log files
SET DOCPROCESS=C:\scripts\e2Vault\process
SET DOCREMOVED=C:\scripts\e2Vault\removed

将是正确的做法。

would be the correct way.

这篇关于传递变量与FORFILES命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆