【问题标题】:Error while searching for the latest file is a directory using a batch file搜索最新文件时出错是使用批处理文件的目录
【发布时间】:2013-06-19 17:54:20
【问题描述】:

我正在尝试创建一个批处理文件来查找目录中的最新文件。我在批处理中使用以下命令:

call cd\
call d:
call cd "D:\OMS\Outbound\"
call for /f "tokens=* delims= " %%G in ('dir /b /od') do set newest=%%G
call pause

我收到错误G was unexpected at this time

我还想通过 ftp 获取最新文件,并且必须按照以下方式在 %%G 之前附加 "local:D:\OMS\Outbound\" newest=local:D:\OMS\Outbound\%G。 从命令提示符运行代码时运行良好,但批处理文件不起作用。

【问题讨论】:

  • 首先,删除每一行中的all标题calls。

标签: batch-file batch-processing


【解决方案1】:
cd /d "D:\OMS\Outbound" for /f "delims=" %%G in ('dir /b /od') 设置 "newest=local:D:\OMS\Outbound\%%~G" 回声%最新% 暂停

并删除其他行。

【讨论】:

  • 谢谢@Endoro。有效。你能告诉我为什么我的命令没有给出所需的结果吗?
  • 不需要call,另见命令行上的call /?
  • /a-d 添加到 DIR 开关以停止包含任何目录名称。
  • 没关系。 tokens= 在将字符串拆分为多个部分时最有价值。 "delims=" 占用整条线路。 %%~G 中的 ~ 在这里不需要,但它不会引起任何问题。它用于删除变量周围的任何双引号。
猜你喜欢
  • 1970-01-01
  • 2014-10-29
  • 2017-04-21
  • 1970-01-01
  • 2020-02-27
  • 2011-11-17
  • 1970-01-01
  • 2014-05-01
  • 1970-01-01
相关资源
最近更新 更多