【问题标题】:dos command to sperate file name and extension into variablesdos命令将文件名和扩展名分隔为变量
【发布时间】:2012-02-03 16:45:57
【问题描述】:

我需要将文件 x.dtsx 从位置 a 复制到位置 b。

如果 b 中已经存在 x.dtsx 那么我需要将 x.dtsx 重命名为 x_Standby.dtsx 然后,在将副本 x.dtsx 重命名为 b 之后

我当前的代码如下所示:

if exists %1 rename %1 %(should be 1_standy.extension)
xcopy %1 %2

【问题讨论】:

  • 我再说一遍:DOS 不是 CMD,[batch-processing] neq [batch=file]

标签: batch-file dos batch-processing batch-rename


【解决方案1】:

如果您使用命令处理器扩展(Windows 2000 和更高版本的默认设置),那么您可以使用以下可选语法:

%~1         - expands %1 removing any surrounding quotes (")
%~f1        - expands %1 to a fully qualified path name
%~d1        - expands %1 to a drive letter only
%~p1        - expands %1 to a path only
%~n1        - expands %1 to a file name only
%~x1        - expands %1 to a file extension only
%~s1        - expanded path contains short names only
%~a1        - expands %1 to file attributes
%~t1        - expands %1 to date/time of file
%~z1        - expands %1 to size of file

修饰符可以组合得到复合结果:

%~dp1       - expands %1 to a drive letter and path only
%~nx1       - expands %1 to a file name and extension only

所以你的命令看起来像这样:

if exist %2\%~nx1 ren %2\%~nx1 %~n1_standby%~x1

【讨论】:

  • 非常感谢 Neil Awesome
猜你喜欢
  • 2017-12-19
  • 1970-01-01
  • 2012-11-13
  • 1970-01-01
  • 2012-12-19
  • 1970-01-01
  • 2011-05-31
  • 1970-01-01
  • 2012-01-02
相关资源
最近更新 更多