Solved

How to extract certain file types from complex folder structure?

Posted on 2010-09-01
6
787 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
[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
6 Comments
 
LVL 55

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 13
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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 13
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 55

Expert Comment

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

~bp
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Simple Linear Regression
Progress

717 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