Solved

How to extract certain file types from complex folder structure?

Posted on 2010-09-01
6
782 Views
Last Modified: 2013-11-10
Hi,
I've a "complex", deep foldere structure on Win7 and want to extract - recursively - all JPEG, all PDFs etc. from this structure and store all to a separate folder. I'm sure this can be done with a small command shell script, but how?
Regards
0
Comment
Question by:go4java
6 Comments
 
LVL 53

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 33575777
If you  want to preserve the directory structure, then you can do this with several xcopy commands, like:

xcopy /s /i c:\source\*.jpg d:\dest

If you want to flatten into a single directory, then this approach can be used in a BAT file:

@echo off
for /F "tokens=*" %%A in ('dir /a-d /b /s "c:\source\*.jpg"') do copy "%%~fA" "d:\dest\%%~nxA"

If you want to add another powerful file copy tool to your toolbox then get a copy of ROBOCOPY from Microsoft (link below that includes the utility) and take a look at it, it can do what you want with a single command but syntax takes a while to learn.

http://technet.microsoft.com/en-us/magazine/2006.11.utilityspotlight.aspx

If you have more than just a couple of extensions you want to copy then we could add a small loop around either of the above first two approaches to process each extension.  An example of this approach can be found in this prior question:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_24889370.html

Hope this helps,

~bp
0
 
LVL 3

Assisted Solution

by:ola_erik
ola_erik earned 250 total points
ID: 33576133
never mind the scripting

get Total Commander
go to the top folder
search for extension and include all subfolders
go to pane
move all hits in pane to some folder

repeat

To preserve the structure, use Xcopy as stated before
0
 
LVL 11

Expert Comment

by:Ben Personick
ID: 33577411
@ola why woudl you use TCommander which must be downloaded and installed and I believe paid for, when there is a perfect solution already availabel natively in the operating system for free and the task itself is obviously perfect for a script?

@Go4JavaI would have written a script almost exactly as Bill did, I think you should go with his methods.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 5

Expert Comment

by:artoaperjan
ID: 33577589
Hi
if you are going to do this only once or once in a year than use the simple search with windows.
if you are going to do this every day then scripting.

if you are going to use the windows search then search the top folder for the extention for example *JPEG and it will find all the files just select them and move them to where you want.
0
 
LVL 11

Expert Comment

by:Ben Personick
ID: 33577691
@art windows search is painfully time consuming if:

1. you are running the classic search (Win XP/2003 and prior)
2. you are running in an unindexed location
3. and IMO even the live search for old versions of windows is really pretty slow. (Honestly I have an issue witht the speed of the search even in Vista.  I think only 7 gets it right.)

ALSO: Using the Windows OS File Copy feature (and the MOVE feature when between different hard disks) requires a lot of additional useless overhead to calculate transfer times and speeds, the script will be much faster.

Also and I knwo here I'm just splitting hairs, but, he didn't mention which MS OS he is running under, it's possible he may even be doing this in MSDOS as he tagged it..  Though I imagine he's probably on XP, 2k3, or 7..
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 33578196
Thanks, glad that was helpful.

~bp
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

838 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