can batch files use date for filename creation?

  • Matthew
  • Proficient
  • Proficient
  • User avatar
  • Posts: 266
  • Loc: Canada

Post 3+ Months Ago

Can batch files use the date for filename creation?

I use batch files and winrar to do daily backups. The only problem is the naming of the rar files. I have to constantly rename them like 0001.rar, 0002.rar, etc.

The question: Can batch files use the date to create a numbering system for the filenames?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Care if I take a look at the batch file you're using to create the b/u? Did you write it, or are you using an automated program to complete this work for you?
  • Matthew
  • Proficient
  • Proficient
  • User avatar
  • Posts: 266
  • Loc: Canada

Post 3+ Months Ago

The batch file is the same one I wrote about here:
http://xona.com/2006/07/05g.html

In that article you can see the dos and windows versions of it, plus a breakdown of the commands. It looks complicated only because of all the winrar switches I use, but the batch file itself is quite simple.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Code: [ Select ]
ECHO Making the copy...
COPY C:\file.txt c:\file_%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.txt
PAUSE
CLS
EXIT
  1. ECHO Making the copy...
  2. COPY C:\file.txt c:\file_%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.txt
  3. PAUSE
  4. CLS
  5. EXIT


EDIT***Make sure not to capture those line breaks if you copy/paste. The COPY goes on one line.
  • Matthew
  • Proficient
  • Proficient
  • User avatar
  • Posts: 266
  • Loc: Canada

Post 3+ Months Ago

Hey, thanks, it worked. Can you break it down and explain it for me?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Sure thing, all you're doing is using the variable %time% here teamed with a command to 'go to X index & pull out Y characters'

%time:~4,2% means grab %time% and go to the index 4, pull out 2 chars

For instance, %time% returns 12:30:57.88

Count up to 3 1(0), 2(1), :(3), 3(4) & copy 2 characters --> '30'

Make sense?
  • Matthew
  • Proficient
  • Proficient
  • User avatar
  • Posts: 266
  • Loc: Canada

Post 3+ Months Ago

Makes sense (although your post and explanation is malformatted if you want to change it).

So %time% and %date% is all I need, with the ":~x,y" command.

Thanks.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Quote:
although your post and explanation is malformatted if you want to change it


Beg your pardon?
  • Matthew
  • Proficient
  • Proficient
  • User avatar
  • Posts: 266
  • Loc: Canada

Post 3+ Months Ago

UPSGuy wrote:
Quote:
although your post and explanation is malformatted if you want to change it


Beg your pardon?

I thought the smiley face was unintended?
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Ahh...okie dokie. I see it now. I have it disabled via my usual desktop PC, but on my laptop I see it now. Thank ya.
  • Matthew
  • Proficient
  • Proficient
  • User avatar
  • Posts: 266
  • Loc: Canada

Post 3+ Months Ago

Now, how do I append a "0" at the beginning of the hours section of the time, to sort my files properly:

07
08
09
10

instead of:

10
7
8
9

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 64 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.