App to change attributes of file

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

  1. MoodyM macrumors 6502a


    Aug 14, 2008
    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:


    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?

  2. mikepro macrumors 6502

    Sep 3, 2010
    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. MoodyM thread starter macrumors 6502a


    Aug 14, 2008
  4. LPZ macrumors 65816

    Jul 11, 2006
    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. mikepro macrumors 6502

    Sep 3, 2010
    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. rockridge98 macrumors newbie

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


    Aug 14, 2008
    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. pitaya macrumors member

    Jun 17, 2012
    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.

     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

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

    Sep 3, 2010
    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 "" 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 (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.

    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){
    	#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) ;
    		if ($startMin >= 60) {
    			$startMin = 0;
    		if ($startHour > 12) {
    		my $ts= $startDate . sprintf ("%02d", $startHour) . sprintf ("%02d", $startMin);
    		my $cmd = "touch  $ts \"$item\" ";
    #		print "cmd is $cmd\n";
    		system ($cmd);

Share This Page