How do I move lots of files based on a list?
September 12, 2007 3:55 PM   Subscribe

Any software out there that can match files from a folder based on a list of keywords, and move the matches to another folder?

Let's say I have a folder filled with 1000 files, each file has a unique index number attached to its file name, but the file types range from PDFs to JPGs.

Examples:
this is a filename[00079].pdf
is this a filename[73822].html
a filename this is[08760].jpg

Now, I have an excel sheet with a list of 400 index numbers. I need to move any file whose attached index number matches the one listed in the excel sheet to another folder.

Is there any software out there that can do this? I know I can do this all by hand, but my real world scenario is close to 5 times more than the example. Plus, I'd rather not spend the time doing this when there is a solution out there because I do this type of monkey-work about once or twice a month.

:)

thanks for all ponderings and sage advice.
posted by nataaniinez to Computers & Internet (9 answers total) 3 users marked this as a favorite
 
Response by poster: an update, Windows Search can do this, although I may need to breakdown the scale each time I run the search:

81892 OR 79329 OR 89398 and so forth

But I am STILL LOOKING for a better way. I need something that can load a list rather than copying and pasting the search terms.
posted by nataaniinez at 4:07 PM on September 12, 2007


Best answer: If you're working on a platofrm with a reasonable shell (in this case bash to be found on many *NIXs including OSX) you can try something like this:

cat text_file_containing_index_numbers_one_per_line | while read index;do mv *[index]* some_new_dir;done;


cat sends the contents of the file, one line at a time to the while loop which mv's any file matching that index number to the new dir/folder indicated.
posted by mce at 4:09 PM on September 12, 2007


Best answer: Try this in a batch file (name it move_by_index.bat or something):

set inputfile=%1
for /F %%a in (%inputfile%) do call move *%%a*.* dest_folder

Dump your indexes into a text file one index per line than run the batch file with the text file as the parameter.

move_by_index.bat list_of_indexes.txt
posted by mphuie at 4:15 PM on September 12, 2007


Didn't preview, mce's is the same solution as mine, but mine runs on windows. That should cover all your bases.
posted by mphuie at 4:17 PM on September 12, 2007


Response by poster: holy shnikeys, both answer look great, will test them out and post the results.
posted by nataaniinez at 4:36 PM on September 12, 2007


Response by poster: the batch script worked wonderfully, going to test the *NIX shell now :)
posted by nataaniinez at 5:18 PM on September 12, 2007


Response by poster: mce:

the *nix shell command doesn't work, gives me this error:

mv: cannot stat `*[index]*': No such file or directory
posted by nataaniinez at 5:29 PM on September 12, 2007


Best answer: Ah whoops! That's my fault for not testing:

"*[index]*" should be *"[$index]"*

so that the variable expansion and wildcard globbing is done properly.
posted by mce at 7:39 PM on September 12, 2007


Response by poster: mce:

sorry homey, it doesn't work, it move all the files into the new dir and gives me this message:

mv: cannot stat '*[123456]*': No such file or directory

where the "123456" is replaced line by line with each of the index numbers in the text list.

Thank you for your input however, I think I will look more into doing this via the bsh as well :)
posted by nataaniinez at 12:00 PM on September 13, 2007


« Older Limo service in Birmingham, AL?   |   I need dynamic pages without PHP or a database.... Newer »
This thread is closed to new comments.