Solved

How to extract certain file types from complex folder structure?

Posted on 2010-09-01
6
780 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 52

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 52

Expert Comment

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

~bp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 145
recursion example 16 111
Make batch file check if file is locked, and open file if not. 10 50
Adoquery sql  left join does not work 25 80
This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now