Number filenames in a folder (oldest first)

Miscellaneous tools
Post Reply
Message
Author
User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

Number filenames in a folder (oldest first)

#1 Post 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


______________________________________________
Attachments
number-files-1.3.pet
put numbers on backend of filenames
(1.73 KiB) Downloaded 462 times
Last edited by don570 on Thu 05 Apr 2012, 17:49, edited 3 times in total.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post 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. :(
Attachments
number-files result 1.jpg
(73.04 KiB) Downloaded 1004 times

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

ls command

#3 Post 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????

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

new version 1.1

#4 Post 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

_____________________________________________________

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#5 Post 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.



________________________________

Post Reply