Page 1 of 1

Number filenames in a folder (oldest first)

Posted: Sat 17 Mar 2012, 19:37
by don570
I wrote a small app to add numbers to filenames in a folder.

The unusual feature is that the number is dependent on the
modification date.

000 is added to the oldest file

It goes up to 999, then it repeats the numbering (I think??)
I haven't tested a folder with a large number of files :oops:

With the method that I used it would be easy to scale the numbers up
00000 to 99999 for instance.

Instructions:

in a terminal you type

Code: Select all

number-files  /some/folder/
A final slash / is optional, but a path is necessary


______________________________________________

Posted: Sun 18 Mar 2012, 03:01
by Flash
I took it for a spin, renumbering the 79 mp3 files in an audio book directory. As you can see, the added numbers are not in the correct order. The files were originally numbered in order of their creation. :(

ls command

Posted: Tue 20 Mar 2012, 16:53
by don570
I'll have to check more carefully. Here's what the internet says:

Code: Select all

6. Order Files Based on Last Modified Time Using ls -lt

To sort the file names displayed in the order of last modification time use the -t option. You will be finding it handy to use it in combination with -l option.

$ ls -lt
total 76
drwxrwxrwt  14 root root  4096 Jun 22 07:36 tmp
drwxr-xr-x 121 root root  4096 Jun 22 07:05 etc
drwxr-xr-x  13 root root 13780 Jun 22 07:04 dev
drwxr-xr-x  13 root root  4096 Jun 20 23:12 root
drwxr-xr-x  12 root root  4096 Jun 18 08:31 home
drwxr-xr-x   2 root root  4096 May 17 21:21 sbin
lrwxrwxrwx   1 root root    11 May 17 20:29 cdrom -> media/cdrom
drwx------   2 root root 16384 May 17 20:29 lost+found
drwxr-xr-x  15 root root  4096 Jul  2  2008 var

but I also used 'touch -a' which may have changed the date of
the original file????

new version 1.1

Posted: Thu 22 Mar 2012, 23:27
by don570
new version 1.1


I tracked down the bug :oops:

I should have read the 'touch' manual more closely.

I have to tell the 'touch' command the file I want the time taken from.

There is a specific option (or switch) for this.

Also I've made sure that over-writing can't occur

by using mv -n

This app is now finished.

Go to rename-files to see the finished product
http://murga-linux.com/puppy/viewtopic.php?t=76919

_____________________________________________________

Posted: Thu 05 Apr 2012, 17:57
by don570
New version 1.3 - Bug fix

To see how this app works in a full fledged utility program
go to Rename-files

I upgraded this app to make it run on all puppies.

I found that it would only work on Lucid Puppy because
of the limitations on the mv command.

It turns out that mv -n (non-clobber) requires a more recent
version of mv.

No file can be over written by this program
so it is safe for use. :lol:

Instructions : Just type in terminal program

Code: Select all

number-files  /some/folder/
The files inside the folder will be numbered safely.
Any folders inside the folder will remain untouched.
A final slash / is optional, but a path is necessary.



________________________________