Solved

.bat to backup certain file adding date and sequence # to end of the file name.

Posted on 2013-05-13
1
324 Views
Last Modified: 2013-06-12
I used to know how to do this, I even wrote them and used them on jobs. I had a couple of handy DOS batch file books once upon a time..

Help save me some time (and if you could also give me a link to a good online batch command resource I'd appreciate it).

I want a batch file to backup this file:

C:\Documents and Settings\Myname\Application Data\Mozilla\Firefox\Profiles\q4lyst7r.default\sessionstore.js

and place it into the folder c:\firefoxback\

I want to name the backups by date and sequentially such as:
sessionstore2013.05.11.01.js
sessionstore2013.05.11.02.js

The current  yyyy.mm.dd.## could be stored in a .txt/.lst file for easy determination of the next name or could be determined by looking at existing file names.
0
Comment
Question by:Missus Miss_Sellaneus
1 Comment
 
LVL 14

Accepted Solution

by:
Giovanni Heward earned 500 total points
ID: 39163144
This should get you started...

@echo off
setlocal enabledelayedexpansion
set mm=%date:~4,2%
set dd=%date:~7,2%
set yyyy=%date:~10,4%
set yy=%date:~12,2%
set source=%userprofile%\Application Data\Mozilla\Firefox\Profiles\q4lyst7r.default\sessionstore.js
set dest=c:\firefoxback
if exist "!source!" (
	for /l %%c in (1,1,8) do (
		set /a check=%%c+1
		if exist "!dest!\sessionstore!yyyy!.!mm!.!dd!.0%%c.js" (
			if not exist "!dest!\sessionstore!yyyy!.!mm!.!dd!.0!check!.js" (
				copy "!source!" "!dest!\sessionstore!yyyy!.!mm!.!dd!.0!check!.js"
				goto :eof
			)
		) else (
			copy "!source!" "!dest!\sessionstore!yyyy!.!mm!.!dd!.0%%c.js"
			goto :eof
		)
	)
)

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now