开发者

Root-Drive-Agnostic copy

开发者 https://www.devze.com 2023-04-01 01:43 出处:网络
I want to write a bat file in windows which would do copy some files into the current directory: copy C:\\Folder1\\Folder2\\file1.ext .\\

I want to write a bat file in windows which would do copy some files into the current directory:

copy C:\Folder1\Folder2\file1.ext .\
copy C:\Folder3\Folder4\Folder5\file2.ext2 开发者_JAVA技巧.\
...

I would like to have the following behavior: If the bat is executed from a path with root drive X, I want it to copy the same files (with the same paths) from X

copy X:\Folder1\Folder2\file1.ext .\
copy X:\Folder3\Folder4\Folder5\file2.ext2 .\
...

How can I achieve this? i.e. how can I get the root drive's name from the current directory? Hope my question was clear.


Can’t you simply leave out the drive letter? AFAIK it’s optional, \Folder\Foo should be a valid absolute path on the current drive.


The rule of batch language is that when you don't know how to do something, it probably involves for.

for /F %%I in ("%CD%") do set CURRENT_DRIVE=%%~dI
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号