App to change attributes of file

Discussion in 'Mac Applications and Mac App Store' started by MoodyM, Jan 3, 2013.

  1. macrumors 6502a

    MoodyM

    Joined:
    Aug 14, 2008
    #1
    I need an app to change the attributes of a whole batch of files, specifically the date created/modified. I have A Better Finder Attributes, but it doesn't have the 1 feature I really need, namely the ability to add some time (a few seconds would do or a day or whatever) to the date created/modified for the next file in the batch.

    For example if I have:

    file1.avi
    file2.avi
    file3.avi

    I want to be able to modify the Date Created for file1.avi to, say, 01 Jan 13, then automatically add, say, 1 day to modify file2.avi to 02 Jan 13 and file3.avi to 03 Jan 13, etc.

    Any ideas?

    Thanks!
     
  2. macrumors 6502

    Joined:
    Sep 3, 2010
    #2
    You can easily do stuff like this in a script or via terminal. Not sure if you have any experience with this stuff, but in a terminal window you can use the command touch to set the timestamp of a file.

    For how the command works, in terminal type:

    man touch

    or just google touch. (Note: Don't actually touch a man based on the command above. ;) ) Basically it will be something like this:

    touch -t 1301021052 file1.avi
    touch -t 1301031052 file2.avi

    will give file1 a date of Jan 2 2013 10:52 am and file2 Jan 3 2013 10:52 am
     
  3. thread starter macrumors 6502a

    MoodyM

    Joined:
    Aug 14, 2008
    #3
    Thanks, but I have over 1000 files to do!
     
  4. LPZ
    macrumors 65816

    Joined:
    Jul 11, 2006
    #4
    Then a shell script that loops through the files and uses touch or SetFile would be one option. Maybe some bash expert will jump in and help you out. Or someone who's more familiar with applications that could do the same thing.
     
  5. macrumors 6502

    Joined:
    Sep 3, 2010
    #5
    OK, describe exactly what you want to do, and maybe I can whip up a quick perl or bash script for you.

    Describe in detail what you want, make sure to include stuff like
    Are all of the files in the same directory?
    How do you determine the timestamp for a file? Based on name? Do you really want the increment to be a day, or an hour, or what?
    Does the starting date matter? Base it off of an existing file?
     
  6. macrumors newbie

    Joined:
    Mar 24, 2012
    #6
    Or just drag all the files you want to change into a folder, cd to that folder, and do
    touch -t 1301031052 *.avi.
     
  7. thread starter macrumors 6502a

    MoodyM

    Joined:
    Aug 14, 2008
    #7
    Basically I have 24 episodes of a TV show in a folder, episodes 1 through 24, named <tv show> Episode 1.avi and so on.

    For some reason my daughter's media player/hard drive will only sort by the date of the file. Since they were all added to the drive on exactly the same date, the box just sorts them seemingly randomly.

    I tried using ABFA to set the Date Created for episode 1 to Jan 1, episode 2 to Jan 2, and so on, and this worked perfectly. Trouble is I have 1000's of other shows/episodes to do!
     
  8. macrumors member

    Joined:
    Jun 17, 2012
    #8
    Here's an example. I don't know how consistent the numbering or filenames are, though. You'll probably have to account for some inconsistencies. Delete the 'echo' when you're ready to run it on files.

    Code:
     days=1; for i in {1..20}; do echo touch -t $(date -v +${days}d -v -1y '+%y%m%d%H%M') "file${i}.avi"; days=$((days+1)); done
    touch -t 1201041731 file1.avi
    touch -t 1201051731 file2.avi
    touch -t 1201061731 file3.avi
    touch -t 1201071731 file4.avi
    touch -t 1201081731 file5.avi
    touch -t 1201091731 file6.avi
    touch -t 1201101731 file7.avi
    touch -t 1201111731 file8.avi
    touch -t 1201121731 file9.avi
    touch -t 1201131731 file10.avi
    touch -t 1201141731 file11.avi
    touch -t 1201151731 file12.avi
    touch -t 1201161731 file13.avi
    touch -t 1201171731 file14.avi
    touch -t 1201181731 file15.avi
    touch -t 1201191731 file16.avi
    touch -t 1201201731 file17.avi
    touch -t 1201211731 file18.avi
    touch -t 1201221731 file19.avi
    touch -t 1201231731 file20.avi
     
  9. LPZ
    macrumors 65816

    Joined:
    Jul 11, 2006
    #9
    No, that won't accomplish what the OP wants. Please read his post carefully.
     
  10. macrumors 6502

    Joined:
    Sep 3, 2010
    #10
    OK, whipped together a quick perl script that will hopefully do what you want. To use this, paste the following code into text edit, and save it as something like "rename.pl" in a directory of your movies. Note this will only work on files in the current directory. So, if you have a bunch of folders, you will have to copy it into each folder and run it.

    To run this, start a terminal window. change to the directory where your movies are. If you don't know how to change directories in terminal, do this:
    type cd
    Open a finder window. Drag the folder that has your movies in it into the terminal window. That will paste the directory into the terminal. Press return. Then, type:
    perl rename.pl (or whatever you named the script. Note, you remembered to copy it into this folder, right?)

    *** USE AT YOUR OWN RISK ****
    I suggest you make a backup copy of files first and do a couple of test runs, as it will change the dates on any avi file in this directory.

    Code:
    use Cwd;
    use strict;
    
    my $dir = getcwd();
    #print "Dir is $dir\n";
    
    #Read test dir contents
    opendir(TESTDIR, $dir);
    my @allFiles = sort readdir(TESTDIR);
    
    #print STDOUT "Got all files:\n\t", join "\n\t",  @allFiles, "\n";
    
    #Start date of 2013 Jan 1  
    my $startDate = "0101" ;
    my $startHour = 1; #1am
    my $startMin = 0;
    my $cnt;
    foreach my $item (@allFiles){
    	chomp($item);
    	#Remove anything that starts with a . (gets rid of ., ..)
     	next if ($item =~/^\./);
    	#print "item is $item\n";
    	
    	if ($item =~ /(.*)(\d+)\.avi$/ ) {
    #		print "Got a match $1  and $2\n";
    #		push (@renameFiles, $item) ;
    		$startMin++;
    		if ($startMin >= 60) {
    			$startHour++;
    			$startMin = 0;
    		}
    		if ($startHour > 12) {
    			$startDate++;
    			$startHour=0;
    		}
    		
    		my $ts= $startDate . sprintf ("%02d", $startHour) . sprintf ("%02d", $startMin);
    		my $cmd = "touch  $ts \"$item\" ";
    #		print "cmd is $cmd\n";
    		system ($cmd);
    	}
    }
    
     

Share This Page