Unix/Linux Go Back    


Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Simple 'date' to 001 scheme script

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-19-2015
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 20 October 2015, 7:24 AM EDT
Posts: 139
Thanks: 26
Thanked 1 Time in 1 Post
Simple 'date' to 001 scheme script

So since I'm looking for an easy way to numberize files in a folder according to date:

Is there an easy script (batch, windows), that will rename files like this:
.earliest creation time: 001.file
older creatiin time : 002.file
even older time : 003.file
....
...
..
.


Any help is appreciated.

te
Sponsored Links
    #2  
Old Unix and Linux 10-19-2015
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 16 February 2017, 11:30 AM EST
Location: Lancashire, UK
Posts: 2,995
Thanks: 1,240
Thanked 569 Times in 516 Posts
Dear pasc,

I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

Assuming that you have less than 1000 files, you could:-
  • Set up a three digit counter padded with leading zeros
  • List the files sort in date order, oldest first (reversed to normal date order) using ls -1rt
  • Use this list as input to a loop to rename each source file in turn to the appropriate numbered file
  • Increment the counter and go round the loop to the end of the list.

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.


Kind regards,
Robin

Last edited by rbatte1; 10-19-2015 at 12:38 PM.. Reason: Polite closing and clarity
Sponsored Links
    #3  
Old Unix and Linux 10-19-2015
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 20 October 2015, 7:24 AM EDT
Posts: 139
Thanks: 26
Thanked 1 Time in 1 Post
it is not a homework assignment.

i merly had imagemagick hack an animated gif into mutiple frames,
edited em w imagemagik and tried to compile as vid with ffmpeg,
but...
sadly the order in the video is wrong
(it jumps from frame 1 to 10 etc)

Thats why I want to rename the files to 0001 0002... to prevent jumping.
    #4  
Old Unix and Linux 10-19-2015
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 19 February 2017, 7:24 PM EST
Location: San Jose, CA, USA
Posts: 9,995
Thanks: 484
Thanked 3,434 Times in 2,934 Posts
Show us the script you're using to get 1.file ... 9.file 10.file... and we'll show you how to simply modify it to produce numbers with a specified number of digits with leading zeros. Note that something like:

Code:
printf '%04d.file' $number

is likely to be at the heart of it (for four digit sequence numbers).
Sponsored Links
    #5  
Old Unix and Linux 10-19-2015
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 20 October 2015, 7:24 AM EDT
Posts: 139
Thanks: 26
Thanked 1 Time in 1 Post
This is the code:

Code:
for %x in (*gif) do convert %x image_%d.gif

Sponsored Links
    #6  
Old Unix and Linux 10-19-2015
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 February 2017, 3:53 PM EST
Location: Saskatchewan
Posts: 21,919
Thanks: 1,049
Thanked 4,094 Times in 3,793 Posts
Ordering by date may not be reliable on extremely small time scales, many implementations only store date to the second. Just moving 1-9, 10-99, 100-999 etc to appropriate four-digit numbers with leading zeroes may be easier. This would be very simple in BASH but excruciatingly difficult in Windows CMD, could you use busybox.exe ?
Sponsored Links
    #7  
Old Unix and Linux 10-20-2015
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 20 October 2015, 7:24 AM EDT
Posts: 139
Thanks: 26
Thanked 1 Time in 1 Post
yes, if it simplifies it, I could.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to do simple date (time) calculation in shell script? nbsparks Shell Programming and Scripting 7 09-16-2013 06:59 PM
Help making simple perl or bash script to create a simple matrix torchij Shell Programming and Scripting 16 04-26-2012 05:05 AM
How can get the value 001 using shell script nmadhuhb Shell Programming and Scripting 2 07-20-2009 07:36 AM
Simple date formatting? muay_tb Shell Programming and Scripting 4 05-01-2009 11:08 AM
a simple way of converting a date in seconds to normal date travian HP-UX 2 11-23-2006 12:25 PM



All times are GMT -4. The time now is 10:17 PM.