?
Solved

Strip Files from Folders into Single Folder

Posted on 2008-06-15
5
Medium Priority
?
447 Views
Last Modified: 2012-06-27
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\AFOLDER123\AFILE.XLS
C:\MYFOLDER\STRUCTURE\BFOLDER456\BFILE.XLS
C:\MYFOLDER\STRUCTURE\CFOLDER7\CFILE.XLS
C:\MYFOLDER\STRUCTURE\DFOLDER8\DFILE.XLS
C:\MYFOLDER\STRUCTURE\EFOLDER99999999\EFILE.XLS

Destination (with how I want my files):
E:\MYFOLDER\STRUCTURE\AFILE.XLS
E:\MYFOLDER\STRUCTURE\BFILE.XLS
E:\MYFOLDER\STRUCTURE\CFILE.XLS
E:\MYFOLDER\STRUCTURE\DFILE.XLS
E:\MYFOLDER\STRUCTURE\EFILE.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\AFOLDER123\*.XLS to C:\MYFOLDER\<WILDCARD>\AFOLDER\*.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.
0
Comment
Question by:andrejonker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 

Author Comment

by:andrejonker
ID: 21788116
Moment of clarity!!! I somehow just figured it out. Consider the following command line solution:

      c:
      cd c:\MYFOLDER\STRUCTURE\
      for /r %a in (*.xls) do xcopy "%a" e:\MYFOLDER\STRUCTURE\*.xls

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 :-)
0
 
LVL 4

Accepted Solution

by:
zveljkovic earned 2000 total points
ID: 21788125
I just wanted to post you a similar solution :)

FOR /R C:\MYFOLDER\STRUCTURE %%f IN (*) DO copy %%f E:\MYFOLDER\STRUCTURE
0
 

Author Closing Comment

by:andrejonker
ID: 31467318
Considering your timing - I will award you some points :-D
0
 

Author Comment

by:andrejonker
ID: 21807470
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.
0
 

Author Comment

by:andrejonker
ID: 21807857
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?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question