Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-05-13
1
Medium Priority
?
331 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 15

Accepted Solution

by:
Giovanni Heward earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
Suggested Courses

876 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