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
精彩评论