如何切换在一个批处理脚本文件的位置? [英] How to switch to file location in a batch script?
本文介绍了如何切换在一个批处理脚本文件的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能(例如)C:\\ File1.exe并将其移动到C:\\ TEMP \\,然后采取C:\\ TEMP \\ File2.exe和移动那里的其他的文件是(C :)上批如果脚本再次执行脚本,然后反转?
How can I take (example) C:\File1.exe and move it to C:\Temp\ and then take C:\Temp\File2.exe and move where the other file was (C:) on a batch script and then reverse if the script is executed again?
推荐答案
下面是一个可能的解决方案。结果
保存为一个批次(例如 swapCopy.bat
。),并与参数调用它,如:结果 swapCopy.batC:\\ File1.exeC:\\ TEMP \\ File2.exe
结果
它会切换的文件,即使文件名和文件夹是相反的。
Here's one possible solution.
Save this as a batch (e. g. swapCopy.bat
) and call it with parameters, like:
swapCopy.bat "C:\File1.exe" "C:\Temp\File2.exe"
It'll switch over the files even if filenames and folders are reversed.
if exist "%~dp1%~nx1" (
if exist "%~dp2%~nx2" (
move "%~dp1%~nx1" "%~dp2%~nx1"
move "%~dp2%~nx2" "%~dp1%~nx2"
goto exit
)
)
if exist "%~dp2%~nx1" (
if exist "%~dp1%~nx2" (
move "%~dp2%~nx1" "%~dp1%~nx1"
move "%~dp1%~nx2" "%~dp2%~nx2"
)
)
:exit
这篇关于如何切换在一个批处理脚本文件的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文