Export files from directory tree?

Discuss anything related to portable freeware here.
Post Reply
Message
Author
eprimetime
Posts: 9
Joined: Sat Oct 21, 2006 7:25 pm

Export files from directory tree?

#1 Post by eprimetime »

I am looking for ANY program, portable or not, but must be free that can handle the following:

I have downloaded a website with WinHTTrack. The directory structure of the downloaded website is fine, and I need to keep it. However, there are MANY files that I don't need for my purposes. Filtering by extension is what I need.

Enter a base directory, and copy the directory structure, and all HTML, PDF, TXT, and graphics (JPG, PNG, GIF) files. No other file type should be copied. The issue is that there are MANY other file types in the directories, from BIN to ZIP to ISO, SYS, DLL, and on and on....I don't need nor want those.

Anyone know of any programs out there that might be able to handle this. I need to keep the original files, but they are VERY large, almost 25 gigs, and making a copy of them and just deleting what I don't need out of the copy is something I've thought about, but do not have the free space on my measly 100 Gig HD.

sgbotsford
Posts: 2
Joined: Sat Dec 01, 2007 7:06 pm

Cygwin...

#2 Post by sgbotsford »

Cygwin (www.cygwin.org, I think) gives you most of Unix functionality in a windows terminal window.

Install cygwin's base package.
Install the file utilities package which should include 'find' and 'grep'

Make a file with a list of the extensions you wish to keep.
call it keepers.txt. Put it in the top of your project directory tree.

cd /cygdrive/{drive}/path/to/project
find . -type f

by itself this command lists all the files, one per line, in that directory tree.

find . -type f | grep -f keepers.txt

The | (read as pipe) means use the output of this program as the input for the next.

grep (Generalized Regular Expression Parser) will read keepers.txt
as a source of patterns, and if the line matches one of them, it will print it.

But these are the ones we want to keep. So invert grep.

find . -type f | grep -v -f keepers.txt

This should list all the files you plan to chuck.

But they go whizzing by so fast!

ok.

find . -type f | grep -v -f keepers.txt | less

Less lets you read the stuff a screenful at a time.

Now you want to do something with this.

Unix generally uses spaces as a separator. You have to jump through hoops if your file name has spaces in it. It also treats certain characaters as special *<>&!() are the ones that come to mind. But lets assume you have nice file names made from [A-Z.a-z,0-9_]

mkdir trash
find . -type f | grep -v -f keepers.txt | xargs -e = -t mv = ./trash

(Not sure of that last -e flag... )
xargs takes the list and uses that name for the move command. (-e = says to replace the = sign in the following command with the line from the previous command. whew!) The -t flag tells xargs to print what it's doing

If this makes you nervous, do it this way:
find . -type f | grep -v -f keepers.txt > chuck.txt
now edit chuck.txt and put a mv with a space in front of each line
and a ./trash with a space before it at the end of each line.

then back in your cygwin window
source chuck.txt

By moving them to trash, you can recover from a mistake fairly gracefully.

jean3167
Posts: 1
Joined: Mon Sep 07, 2009 2:08 am

Re: Export files from directory tree?

#3 Post by jean3167 »

Quite good directory treeview tool called print directory not a freeware but affortable.

Nani
Posts: 2
Joined: Fri Sep 11, 2009 5:30 pm

Re: Export files from directory tree?

#4 Post by Nani »


JwG
Posts: 2
Joined: Wed Sep 16, 2009 10:05 am

Re: Export files from directory tree?

#5 Post by JwG »

Robocopy will do this:

Command string:
Robocopy frompath topath *.htm* *.gif *.PDF *.TXT *.JPG *.PNG *.GIF /options

Options
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.

I believe it is included in Vista, but it is a free download from Microsoft if you have XP or something earlier.
http://www.microsoft.com/Downloads/deta ... laylang=en

User avatar
webfork
Posts: 10821
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: Export files from directory tree?

#6 Post by webfork »

I would just find a search tool that does an exclude function and just add the terms you mentioned. Then, with the results, just select all and delete. Here's two search programs I use regularly, both free, one portable.

1. Everything http://www.portablefreeware.com/index.php?id=1479: to exclude something from the search include a ! at the front of the term.

Code: Select all

c:\whatever\directory\  !*.htm !*.html !*.gif !*.pdf !*.txt !*.jpg !*.png !*.gif
2. Copernic Desktop Search http://www.copernic.com/en/products/desktop-search/: to exclude something from the search include a NOT and separate by commas:

Code: Select all

C:\whatever\directory\*.*, NOT *.htm, NOT *.html, NOT *.gif, NOT *.pdf, NOT *.txt, NOT *.jpg, NOT *.png
For Copernic, you have to make sure the folder in question is indexed, which you can check in the "Tools" menu under "Options" - "Files"

Post Reply