Solved

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

Posted on 2013-05-13
1
327 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

This is about my first experience with programming Arduino.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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