Solved

How to extract certain file types from complex folder structure?

Posted on 2010-09-01
6
776 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 51

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 to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 51

Expert Comment

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

~bp
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 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…

706 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

20 Experts available now in Live!

Get 1:1 Help Now