2012-01-05 26 views
9

Tôi cần phải sao chép tệp x.dtsx từ vị trí a sang vị trí b.lệnh dos để chia nhỏ tên tệp và tiện ích mở rộng thành các biến

Nếu x.dtsx đã tồn tại trong b sau đó tôi cần phải đổi tên x.dtsx để x_Standby.dtsx Sau đó, sau khi đổi tên bản sao x.dtsx để b

mã hiện tại của tôi trông như thế này:

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

Và tôi nhắc lại: DOS không phải là CMD, và '[hàng loạt chế biến] NEQ [mẻ = file]' – SteveFest

Trả lời

34

Nếu bạn sử dụng Extensions Processor Command (đó là mặc định trên Windows 2000 và sau này) sau đó bạn có thể sử dụng cú pháp tùy chọn sau đây:

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

các bổ trợ có thể kết hợp để có được compo kết quả und:

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

Vì vậy, lệnh của bạn sẽ trông như thế này:

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

Thank bạn rất nhiều Neil Awesome –

Các vấn đề liên quan