Jump to content

[CMD/VBS] - Add date to filename or folder name


Recommended Posts

I'm trying to find a way of running 7-zip to archive my "My Documents" folder and store it in a file that contains the date (and possibly time) in the filename for quick reference of when the last backup was made.

The "date /T" command in XP provides the date, but the string contains slashes, which XP doesn't like for filenames (for obvious reasons).

Any leads as to how to do this would be appreciated. Even just an example of how to make a .txt file with the date as part of the filename.

Thanks in advance. :)

Link to comment
Share on other sites


Any leads as to how to do this would be appreciated. Even just an example of how to make a .txt file with the date as part of the filename.

Thanks in advance. :)

NAMEDATE Version 5.03

Copyright © 1999, 2002-2005 by James Greene. All rights reserved.

http://www.informatics-consulting.ch

NAMEDATE adds a date to a given file's name.

Usage:

NAMEDATE.EXE [switches] filenames(s)

where [switches] may be

(**) /F = put the date before the original filename

(**) /X = put the date as an extension to the original filename

(*) /8 = Use DOS 8.3 filenames (xxYYMMDD.ext)

/Z:"[format]" = date format (see documentation)

/ZZ:"[format]" = enhanced format (see documentation) (new in v5.0)

/M = use the file's modification date/time

/O+[d] = add [d] days to the date

/O-[d] = subtract [d] days from the date

/A+[m] = add [m] minutes to the time

/A-[m] = subtract [m] minutes from the time

Link to comment
Share on other sites

The "date /T" command in XP provides the date, but the string contains slashes, which XP doesn't like for filenames (for obvious reasons).

here is a solution to name a file using YYYYMMDD format, providing that system date format is MM/DD/YYYY

@echo off
setlocal enableextensions

set arcname=MyDocs_%date:~-4%%date:~0,2%%date:~3,2%.7z

echo Making archive : %arcname%...

rem call 7za here

Link to comment
Share on other sites

Here is some more VBS for the time, sorry I made a mistake in my first post thought you wanted dated.

MsgBox Hour(Now) & "_" & Minute(Now) & "_" & Second(Now)
Dim T1 : T1 = Replace(Time,":","_") : MsgBox T1

Edited by gunsmokingman
Link to comment
Share on other sites

  • 2 weeks later...

Wow... this is a lot better than I had originally hoped. Thank you all very much for the help.

I really should start learning VBS. gunsmokingman - where did you pick up VBS? Any good online tutorials? I know that someone posted a few links to some here a while back, but that post was probably close to a year ago.

Link to comment
Share on other sites

Try this, it sets the variables in the batch file for use later on within it...

@Echo off

::Setting Path Variables

Set BACKUPDIR=C:

Set TARGET=%USERPROFILE%\MYDOCU~1

Set ZIPEXE=C:

::Grabbing date variables...

@For /F "tokens=1 delims=/ " %%A in ('Date /t') do set DD=%%A
@For /F "tokens=2 delims=/ " %%B in ('Date /t') do set MM=%%B
@For /F "tokens=3 delims=/ " %%C in ('Date /t') do set YY=%%C

Set CUSTOMDATE=%DD%-%MM%-%YY%

:: Running7Z...

start /wait %ZIPEXE%\7za.exe a -tzip %BACKUPDIR%\MyDoc%CUSTOMDATE%.zip "%TARGET%\*"

Exit

Hope this helps you. :thumbup

SilverB.

Edited by SilverBulletUK
Link to comment
Share on other sites

Wow... this is a lot better than I had originally hoped. Thank you all very much for the help.

I really should start learning VBS. gunsmokingman - where did you pick up VBS? Any good online tutorials? I know that someone posted a few links to some here a while back, but that post was probably close to a year ago.

I go here to learn about VBS scripting The Hey, Scripting Guy! Archive they have a lot of templates and links to more information.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...