Renaming files

Questions? Suggestions? Need help? Talk about anything related to Yawcam...
malun
Site Admin
Posts: 1493
Joined: Sun Jan 04, 2004 1:29 pm

Renaming files

Postby malun » Mon Jun 07, 2004 4:53 pm

I got a mail from Thomas Schrenk who has wrote a small and efficient script that renames files. This is useful when saving image arrays.

His mail describes the problem area and shows the script:

Hello Magnus,

today I found Yawcam when looking for a software for tracking a corner in my house basement where occasionally water gets in.

It is a great software with perfect functionality, thanks a lot that you made this freeware.

When playing with it and saving files to another server for harddisk purpose I realized that the sequence of the created pictures starts again with 0, 1, 2 when the files are moved. Therefore I found it a bit confusing to track the timely sequence when watching the pictures since the imageviewers sort image1, image11, image111, image2, image3 etc.

Therefore I wrote a small Per script that renames the files by putting Year-Month-Day-hour-minute before the filename. So the sorting is correct when viewing the images.

I thought it could be useful to share.

Requirements is the installation of the Perl modules from Activeperl(http://www.activestate.com/Products/ActivePerl/?_x=1).

The perl script does a dir *.jpg and combines the new filename out of the columns and finally renames the files.


Here a basic screen output and the script:
K:\>dir *.jpg
Volume in drive K has no label.
Volume Serial Number is 07D1-061A

Directory of K:\

06.06.2004 22:59 60.939 keller0.jpg
06.06.2004 23:00 61.125 keller1.jpg
06.06.2004 23:01 61.393 keller2.jpg
06.06.2004 23:02 61.120 keller3.jpg
06.06.2004 23:03 60.953 keller4.jpg
06.06.2004 23:04 61.187 keller5.jpg
06.06.2004 23:06 61.029 keller6.jpg
06.06.2004 23:07 61.157 keller7.jpg
06.06.2004 23:08 61.532 keller8.jpg
06.06.2004 23:09 61.228 keller9.jpg
10 File(s) 611.663 bytes
0 Dir(s) 749.387.776 bytes free


K:\>perl filerename.txt
rename keller0.jpg->2004-06-06-22-59-keller0.jpg
rename keller1.jpg->2004-06-06-23-00-keller1.jpg
rename keller2.jpg->2004-06-06-23-01-keller2.jpg
rename keller3.jpg->2004-06-06-23-02-keller3.jpg
rename keller4.jpg->2004-06-06-23-03-keller4.jpg
rename keller5.jpg->2004-06-06-23-04-keller5.jpg
rename keller6.jpg->2004-06-06-23-06-keller6.jpg
rename keller7.jpg->2004-06-06-23-07-keller7.jpg
rename keller8.jpg->2004-06-06-23-08-keller8.jpg
rename keller9.jpg->2004-06-06-23-09-keller9.jpg

K:\>type filerename.txt
system "dir *.jpg >xxx.txt";

open (WINDIR, "xxx.txt");
while ($line=<WINDIR>) {


$s=substr($line,0,1); #Erste Spalte numerisch, sonst keine Datei



if ($s =~ /[0-9]/) {
#print "$line";
$year=substr($line,6,4);
$month=substr($line,3,2);
$day=substr($line,0,2);
$hh=substr($line,12,2);
$mm=substr($line,15,2);
$orgfilename=substr($line,39,length($line)-40);

$newfilename="$year-$month-$day-$hh-$mm-$orgfilename";



print "rename $orgfilename->$newfilename\n";

rename ($orgfilename,$newfilename);

}
}



Best Regards

Thomas Schrenk


Perhaps this functionality could be built-in in Yawcam some day :wink:
But until then use this script! It works like a charm!
Thanx Thomas!

/malun
Last edited by malun on Thu Apr 27, 2006 7:54 pm, edited 3 times in total.

Advertisement



malun
Site Admin
Posts: 1493
Joined: Sun Jan 04, 2004 1:29 pm

Postby malun » Mon Jun 07, 2004 4:58 pm

I just realized that this script only will work correct if you use the english version of Microsoft Windows. (Or a version with the same date format) But it is easy to modify so it fits your system. Here is a modified version that works with the swedish date format:

Code: Select all

system "dir *.jpg >xxx.txt";

open (WINDIR, "xxx.txt");
while ($line=<WINDIR>) {


$s=substr($line,0,1); #Erste Spalte numerisch, sonst keine Datei



if ($s =~ /[0-9]/) {
#print "$line";
$year=substr($line,0,4);
$month=substr($line,5,2);
$day=substr($line,8,2);
$hh=substr($line,12,2);
$mm=substr($line,15,2);
$orgfilename=substr($line,36,length($line)-37);

$newfilename="$year-$month-$day-$hh-$mm-$orgfilename";



print "rename $orgfilename->$newfilename\n";

rename ($orgfilename,$newfilename);

}
}


/malun

malun
Site Admin
Posts: 1493
Joined: Sun Jan 04, 2004 1:29 pm

Postby malun » Thu Apr 27, 2006 7:54 pm

In the latest beta version of Yawcam you have better control over the file names and can include date and timestamps.
So if yo use a version of Yawcam released later than 2006-04-10 this script won't be needed.

/malun

barcajunior
Posts: 1
Joined: Tue Jan 15, 2008 2:59 pm

Postby barcajunior » Tue Jan 15, 2008 3:07 pm

You needn't worry about the question in the latest version of Yawcam.

chatrouletter
Posts: 5
Joined: Fri Mar 25, 2011 5:37 pm

Postby chatrouletter » Sat Mar 26, 2011 5:58 pm

Do you need to run a script to re-name files or can you go in and manually make changes? I am a fan of customization. Right now I am running Yawcam combined with hosted PBX and dvd burning software which has resulted in the ultimate video chatting and recording experience. It really helps when you are running a small business out of your home.
Last edited by chatrouletter on Wed Feb 22, 2012 7:14 pm, edited 1 time in total.

Yanka
Posts: 3
Joined: Mon Mar 12, 2012 3:05 pm

Postby Yanka » Mon Mar 12, 2012 3:11 pm

Do you get an error message in the log when you try to rename?

roderick
Posts: 3
Joined: Wed Mar 14, 2012 1:03 pm

Postby roderick » Wed Mar 14, 2012 1:26 pm

malun wrote:I just realized that this script only will work correct if you use the english version of Microsoft Windows. (Or a version with the same date format) But it is easy to modify so it fits your system. Here is a modified version that works with the swedish date format:

Code: Select all

system "dir *.jpg >xxx.txt";

open (WINDIR, "xxx.txt");
while ($line=<WINDIR>) {


$s=substr($line,0,1); #Erste Spalte numerisch, sonst keine Datei



if ($s =~ /[0-9]/) {
#print "$line";
$year=substr($line,0,4);
$month=substr($line,5,2);
$day=substr($line,8,2);
$hh=substr($line,12,2);
$mm=substr($line,15,2);
$orgfilename=substr($line,36,length($line)-37);

$newfilename="$year-$month-$day-$hh-$mm-$orgfilename";



print "rename $orgfilename->$newfilename\n";

rename ($orgfilename,$newfilename);

}
}


/malun

I have a german version of Windows 7. How can i make use of the following script without reinstalling another version of Win7?

______________________________
cell phone tracker
Last edited by roderick on Fri Apr 27, 2012 7:27 am, edited 1 time in total.

memoric
Posts: 184
Joined: Wed Feb 23, 2011 1:37 pm

Postby memoric » Wed Mar 14, 2012 2:43 pm

First of all you should run "cmd.exe". Then type "cd\" (without the quotes "").
That should get you to C:\. Then type "dir *.txt>xxx.txt" (note that you should
have at least one text file in C:\, if not create one). Finally close cmd & go to
your C:\ folder. There should be a file named "xxx.txt". Open it & post here
one of its lines, for example "31/03/2011 11:24 31.722 ASLog.txt". After I see
what's your system's date format I can tell you how to modify the script.


Return to “General”

Who is online

Users browsing this forum: No registered users and 9 guests