加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

batch-file-dos命令将文件名和扩展名分解成变量

发布时间:2020-12-14 01:41:47 所属栏目:Windows 来源:网络整理
导读:我需要将文件x.dtsx从位置a复制到位置b. 如果x.dtsx已经存在于b中,那么我需要将x.dtsx重命名为x_Standby.dtsx然后,将x.dtsx重命名为b后 我当前的代码如下所示: if exists %1 rename %1 %(should be 1_standy.extension)xcopy %1 %2 如果使用命令处理器扩展(
我需要将文件x.dtsx从位置a复制到位置b.

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

我当前的代码如下所示:

if exists %1 rename %1 %(should be 1_standy.extension)
xcopy %1 %2
如果使用命令处理器扩展(在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读