Solved

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

Posted on 2013-05-13
1
326 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide http port number 5 51
ejb message driven bean mdb creation steps 2 23
storing csv file in table variable in Python 2 26
AvlTree-Node Data type 4 14
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

860 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