DOS命令sperate文件名和扩展到变量 [英] dos command to sperate file name and extension into variables

查看:384
本文介绍了DOS命令sperate文件名和扩展到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从位置的文件x.dtsx复制到B位置。

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

我目前的code是这样的:

 是否存在%1重命名%1%(应该是1_standy.extension)
XCOPY%1%2


解决方案

如果您使用命令处理程序扩展(这是默认情况下在Windows 2000及更高版本),那么你可以使用下列选项语法:

 %〜1  - 扩展1%删除任何引号()
%〜F1 - %1扩充到一个完全合格的路径名
%〜D1 - %1扩展到一个驱动器号
%〜P1 - %1扩充到一个路径
%〜N1 - %1扩展到一个文件名
%〜X1 - %1扩展到一个文件扩展名
%〜S1 - 扩充的路径只含有短名
%〜a1 - 将%1扩展到文件属性
%〜T1 - %1扩展到文件的日期/时间
%〜Z1 - %1扩展到文件的大小

的改性剂可被组合以获得化合物的结果:

 %〜DP1  - %1扩展到一个驱动器号和路径只
%〜NX1 - %1扩展到文件名和扩展名

所以,你的命令应该是这个样子:

 是否存在%2 \\%〜NX1仁%2 \\%〜NX1%〜n1_standby%〜X1

I need to copy a file x.dtsx from location a to location b.

If x.dtsx already exists in b then I need to rename x.dtsx to x_Standby.dtsx Then, after renaming copy x.dtsx to b

My current code looks like this:

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

解决方案

If you use the Command Processor Extensions (which is default on Windows 2000 and later) then you can use the following optional syntax:

%~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

The modifiers can be combined to get compound results:

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

So your command would look something like this:

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

这篇关于DOS命令sperate文件名和扩展到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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