weklica
asked on
Copy even or odd files
I need to copy even numbered or odd numbered files from a folder or CD into a new directory. The name of the files are literally 1 2 3 4 5 6 7
So, how do I copy only even or only odd files?
I would like this to work in windows and MAC. So, I am looking for a batch file version and maybe an applescript that may work.
So, how do I copy only even or only odd files?
I would like this to work in windows and MAC. So, I am looking for a batch file version and maybe an applescript that may work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, my solution was an example, since your original post didn't indicate which you wanted to copy (even or odd) I showed how you could separate based on filename, and then act accordingly.
~bp
~bp
ASKER
ah, i did edit the directories, but not the 'even or odd' rather, made those as directories thinking the files would dump into those folders. my bad. will try again. Thanks
If you like this to work in windows(cmd.exe) and MAC, then i recommend a cross platform programming language, eg, Python or Perl. Here's a Perl snippets (similarly can be done with Python). The advantage to this method is that you maintain only 1 script and of course, you must have these programming language installed before you can use.
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
my $destination="/destination" ; #put destination here
while(my $file=<[0-9]*>){
if ( $file % 2 eq 1 ){
print $file ."\n";
copy($file,$destination) or die "Copy failed: $!";
}
}
ASKER
Sorry for delay, was waiting for MAC comment. Windows worked fine. Thanks much!
ASKER
TGERBERT: YOUR SOLUTION WORKED WELL.