andrejonker
asked on
Strip Files from Folders into Single Folder
I am trying to find a XCOPY or ROBOCOPY solution to Strip Files from a Folder Structure into a Single Folder.
Here follows an example.
Source Structure:
C:\MYFOLDER\STRUCTURE\AFOL DER123\AFI LE.XLS
C:\MYFOLDER\STRUCTURE\BFOL DER456\BFI LE.XLS
C:\MYFOLDER\STRUCTURE\CFOL DER7\CFILE .XLS
C:\MYFOLDER\STRUCTURE\DFOL DER8\DFILE .XLS
C:\MYFOLDER\STRUCTURE\EFOL DER9999999 9\EFILE.XL S
Destination (with how I want my files):
E:\MYFOLDER\STRUCTURE\AFIL E.XLS
E:\MYFOLDER\STRUCTURE\BFIL E.XLS
E:\MYFOLDER\STRUCTURE\CFIL E.XLS
E:\MYFOLDER\STRUCTURE\DFIL E.XLS
E:\MYFOLDER\STRUCTURE\EFIL E.XLS
The above requirement appeared so straight forward when I took it on, but I have not been able to find the right XCOPY or ROBOCOPY parameters to achieve this. I would expect the solution to be some way of using a wildcard foldername to translate C:\MYFOLDER\STRUCTURE\AFOL DER123\*.X LS to C:\MYFOLDER\<WILDCARD>\AFO LDER\*.XLS so I can achieve something like this:
XCOPY C:\MYFOLDER\STRUCTURE\*\*. XLS E:\MYFOLDER\STRUCTURE\
Unfortuntately you cannot use an asterisk to wildcard a foldername as above.
Please do not suggest using a recursive folder switch such as /S, because I can assure you that the following will not produce the required result:
XCOPY /S C:\MYFOLDER\STRUCTURE\ E:\MYFOLDER\STRUCTURE\
The structure from which we need to strip the files will be reproduced with the /S recursive switch.
Any assistance in this matter will be greatly appreciated.
Here follows an example.
Source Structure:
C:\MYFOLDER\STRUCTURE\AFOL
C:\MYFOLDER\STRUCTURE\BFOL
C:\MYFOLDER\STRUCTURE\CFOL
C:\MYFOLDER\STRUCTURE\DFOL
C:\MYFOLDER\STRUCTURE\EFOL
Destination (with how I want my files):
E:\MYFOLDER\STRUCTURE\AFIL
E:\MYFOLDER\STRUCTURE\BFIL
E:\MYFOLDER\STRUCTURE\CFIL
E:\MYFOLDER\STRUCTURE\DFIL
E:\MYFOLDER\STRUCTURE\EFIL
The above requirement appeared so straight forward when I took it on, but I have not been able to find the right XCOPY or ROBOCOPY parameters to achieve this. I would expect the solution to be some way of using a wildcard foldername to translate C:\MYFOLDER\STRUCTURE\AFOL
XCOPY C:\MYFOLDER\STRUCTURE\*\*.
Unfortuntately you cannot use an asterisk to wildcard a foldername as above.
Please do not suggest using a recursive folder switch such as /S, because I can assure you that the following will not produce the required result:
XCOPY /S C:\MYFOLDER\STRUCTURE\ E:\MYFOLDER\STRUCTURE\
The structure from which we need to strip the files will be reproduced with the /S recursive switch.
Any assistance in this matter will be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Considering your timing - I will award you some points :-D
ASKER
Big oops... I did not test zveljkovic's suggestion.
I get the following error:
%%f was unexpected at this time.
I changed to %%f to %a as follows:
for /r C:\MYFOLDER\STRUCTURE %a in (*.txt) do xcopy "%a" e:\MYFOLDER\STRUCTRE\*.txt
Note the quotes around the second %a as in "%a". This is to cater for long file/folder names with spaces.
I get the following error:
%%f was unexpected at this time.
I changed to %%f to %a as follows:
for /r C:\MYFOLDER\STRUCTURE %a in (*.txt) do xcopy "%a" e:\MYFOLDER\STRUCTRE\*.txt
Note the quotes around the second %a as in "%a". This is to cater for long file/folder names with spaces.
ASKER
The error again came up... This time when I put the above in a batch script... seems the %%f was correct after all. Seems the rule is:
for CLI use one % and for CMD use two?
for CLI use one % and for CMD use two?
ASKER
c:
cd c:\MYFOLDER\STRUCTURE\
for /r %a in (*.xls) do xcopy "%a" e:\MYFOLDER\STRUCTURE\*.xl
If you can improve on the above, or point out a real show-stopper issue with using this as a solution, I will award the points. Else, this issue is considered resolved :-)