问题
How can I copy series of files located in one folder into a specified folder based on the each file name in Windows?
For example the files:
ProviderA.pdf copied to folder-> \ProviderA\report\
ProviderB.pdf copied to folder-> \ProviderB\report\
ProviderC.pdf copied to folder-> \ProviderC\report\
I would like to traverse the list of files and from the file name (minus the extension) be able to copy each file to the folder specified by the file name.
Thank you in advance!
回答1:
dir /b *.pdf >foo
for /f "tokens=1 delims=. " %i in (foo) do copy %i.pdf %i\report
del foo
If the directories don't already exist, substitute this command:
for /f "tokens=1 delims=. " %i in (foo) do md %i\report© %i.pdf %i\report
回答2:
Simplest way is to loop through files in current folder, create a folder using the filename (without the extension) if it doesn't already exist, then copy file into the new folder.
for %%G in (*.pdf) do (
if not exist %%~nG md %%~nG
copy %%G %%~nG
)
来源:https://stackoverflow.com/questions/7651406/copy-a-set-of-files-into-specific-directories-based-on-filename