Link to home
Start Free TrialLog in
Avatar of weklica
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.  
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of weklica
weklica

ASKER

BILLPREW:  YOUR VERSION COPIES ALL OF THE NUMBERED FILES INTO ODD AND THE NON NUMERIC FILES INTO EVEN.  I AM SURE IT IS CLOSE, SOME SMALL ERROR?

TGERBERT: YOUR SOLUTION WORKED WELL.
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
Avatar of weklica

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: $!";
   }
}

Open in new window

Avatar of weklica

ASKER

Sorry for delay, was waiting for MAC comment.  Windows worked fine.  Thanks much!