Batch File: Backup one file & add the date. - Microsoft Windows

This is a discussion on Batch File: Backup one file & add the date. - Microsoft Windows ; Hi everyone, I'm a complete novice at batch files. I'd like to know a code I can use to backup a file automatically when I start my PC (I figure I could just throw the batch file into my startup ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: Batch File: Backup one file & add the date.

  1. Batch File: Backup one file & add the date.

    Hi everyone,

    I'm a complete novice at batch files. I'd like to know a code I can
    use to backup a file automatically when I start my PC (I figure I could
    just throw the batch file into my startup folder). The file I need to
    backup is called 'editsdb.mdb' and I'd like the batch file to make a
    copy of it and throw it in a backup folder with the date at the
    beginning (10262005editsdb.mdb).
    Is this possible?

    Thanks!
    Steve


  2. Re: Batch File: Backup one file & add the date.

    echo | more | date > temp.bat
    echo copy c:\editsdb.mdb "c:\backup\%%4editsdb.mdb" > current.bat
    call temp.bat
    del current.bat
    del temp.bat
    ::end

    Ben

    "stevethrewup" wrote in message news:1130353686.325594.11210@g14g2000cwa.googlegro ups.com...
    > Hi everyone,
    >
    > I'm a complete novice at batch files. I'd like to know a code I can
    > use to backup a file automatically when I start my PC (I figure I could
    > just throw the batch file into my startup folder). The file I need to
    > backup is called 'editsdb.mdb' and I'd like the batch file to make a
    > copy of it and throw it in a backup folder with the date at the
    > beginning (10262005editsdb.mdb).
    > Is this possible?
    >
    > Thanks!
    > Steve
    >


  3. Re: Batch File: Backup one file & add the date.

    Hmmm, I think I am doing something wrong. Here is the DOS text I get
    when I run the BAT with the correct file/folder in place:

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    O:\>c:\
    'c:\' is not recognized as an internal or external command,
    operable program or batch file.

    O:\>c:

    C:\>backup

    C:\>echo | more | date 1>temp.bat

    C:\>echo copy c:\editsdb.mdb c:\backup\%4editsdb.mdb 1>current.bat

    C:\>call temp.bat

    C:\>The current date is: Thu 10/27/2005
    'The' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>Enter the new date: (mm-dd-yy) ECHO is on.
    'Enter' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>The system cannot accept the date entered.
    'The' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>Enter the new date: (mm-dd-yy)
    'Enter' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>del current.bat

    C:\>del temp.bat
    C:\>



    Ben Myers wrote:
    > echo | more | date > temp.bat
    > echo copy c:\editsdb.mdb "c:\backup\%%4editsdb.mdb" > current.bat
    > call temp.bat
    > del current.bat
    > del temp.bat
    > ::end
    >
    > Ben
    >
    > "stevethrewup" wrote in message news:1130353686.325594.11210@g14g2000cwa.googlegro ups.com...
    > > Hi everyone,
    > >
    > > I'm a complete novice at batch files. I'd like to know a code I can
    > > use to backup a file automatically when I start my PC (I figure I could
    > > just throw the batch file into my startup folder). The file I need to
    > > backup is called 'editsdb.mdb' and I'd like the batch file to make a
    > > copy of it and throw it in a backup folder with the date at the
    > > beginning (10262005editsdb.mdb).
    > > Is this possible?
    > >
    > > Thanks!
    > > Steve
    > >



  4. Re: Batch File: Backup one file & add the date.

    Try this instead.

    echo | more | date > temp.bat
    echo copy c:\editsdb.mdb "c:\backup\%%5editsdb.mdb" > the.bat
    call temp.bat
    del the.bat
    del temp.bat

    Ben

    "stevethrewup" wrote in message news:1130425132.908429.300940@g14g2000cwa.googlegr oups.com...
    > Hmmm, I think I am doing something wrong. Here is the DOS text I get
    > when I run the BAT with the correct file/folder in place:
    >
    > Microsoft Windows XP [Version 5.1.2600]
    > (C) Copyright 1985-2001 Microsoft Corp.
    >
    > O:\>c:\
    > 'c:\' is not recognized as an internal or external command,
    > operable program or batch file.
    >
    > O:\>c:
    >
    > C:\>backup
    >
    > C:\>echo | more | date 1>temp.bat
    >
    > C:\>echo copy c:\editsdb.mdb c:\backup\%4editsdb.mdb 1>current.bat
    >
    > C:\>call temp.bat
    >
    > C:\>The current date is: Thu 10/27/2005
    > 'The' is not recognized as an internal or external command,
    > operable program or batch file.
    >
    > C:\>Enter the new date: (mm-dd-yy) ECHO is on.
    > 'Enter' is not recognized as an internal or external command,
    > operable program or batch file.
    >
    > C:\>The system cannot accept the date entered.
    > 'The' is not recognized as an internal or external command,
    > operable program or batch file.
    >
    > C:\>Enter the new date: (mm-dd-yy)
    > 'Enter' is not recognized as an internal or external command,
    > operable program or batch file.
    >
    > C:\>del current.bat
    >
    > C:\>del temp.bat
    > C:\>

    >
    >
    > Ben Myers wrote:
    > > echo | more | date > temp.bat
    > > echo copy c:\editsdb.mdb "c:\backup\%%4editsdb.mdb" > current.bat
    > > call temp.bat
    > > del current.bat
    > > del temp.bat
    > > ::end
    > >
    > > Ben
    > >
    > > "stevethrewup" wrote in message news:1130353686.325594.11210@g14g2000cwa.googlegro ups.com...
    > > > Hi everyone,
    > > >
    > > > I'm a complete novice at batch files. I'd like to know a code I can
    > > > use to backup a file automatically when I start my PC (I figure I could
    > > > just throw the batch file into my startup folder). The file I need to
    > > > backup is called 'editsdb.mdb' and I'd like the batch file to make a
    > > > copy of it and throw it in a backup folder with the date at the
    > > > beginning (10262005editsdb.mdb).
    > > > Is this possible?
    > > >
    > > > Thanks!
    > > > Steve
    > > >

    >


  5. Re: Batch File: Backup one file & add the date.

    I'm getting further with it but I'm still having problems. Perhaps the
    "/" in the filename is what is causing the problem? Here is the new
    DOS text:

    C:\>backup

    C:\>echo | more | date 1>temp.bat

    C:\>echo copy c:\editsdb.mdb "c:\backup\%5editsdb.mdb" 1>the.bat

    C:\>call temp.bat

    C:\>The current date is: Thu 10/27/2005

    C:\>copy c:\editsdb.mdb "c:\backup\10/27/2005editsdb.mdb"
    The system cannot find the path specified.
    0 file(s) copied.

    C:\>del the.bat

    C:\>del temp.bat

    C:\>

    Thanks so much for you help!
    Steve


  6. Re: Batch File: Backup one file & add the date.

    echo | more | date > temp.bat
    echo set date=%%5 > the.bat
    echo copy d:\editsdb.mdb "d:\backup\%%date:/=%%editsdb.mdb" >> the.bat
    call temp.bat
    set date=
    del the.bat
    del temp.bat

    Ben

    "stevethrewup" wrote in message news:1130438900.112088.52140@f14g2000cwb.googlegro ups.com...
    > I'm getting further with it but I'm still having problems. Perhaps the
    > "/" in the filename is what is causing the problem? Here is the new
    > DOS text:
    >
    > C:\>backup
    >
    > C:\>echo | more | date 1>temp.bat
    >
    > C:\>echo copy c:\editsdb.mdb "c:\backup\%5editsdb.mdb" 1>the.bat
    >
    > C:\>call temp.bat
    >
    > C:\>The current date is: Thu 10/27/2005
    >
    > C:\>copy c:\editsdb.mdb "c:\backup\10/27/2005editsdb.mdb"
    > The system cannot find the path specified.
    > 0 file(s) copied.
    >
    > C:\>del the.bat
    >
    > C:\>del temp.bat
    >
    > C:\>
    >
    > Thanks so much for you help!
    > Steve
    >


  7. Re: Batch File: Backup one file & add the date.

    IT WORKS!! Thank you so much Ben! You've saved me so much time and
    greif!


  8. Re: Batch File: Backup one file & add the date.

    Is there also a way to delete the same file if it's more than 60 days
    old?

    Thanks!


  9. Re: Batch File: Backup one file & add the date.

    "stevethrewup" writes:
    > Is there also a way to delete the same file if it's more than 60 days
    > old?


    Download cygwin. http://cygwin.com/

    Use the find command from the cygwin shell.

    find /cygdrive/c/path/to/work/on -mtime +60 \! -type d -exec rm {} \;

    Be careful with the path there, as it's gonna wipe out anything older
    than 60 days in that whole subtree. It will spare directories in the
    example above ("find files in this path where the file was modified
    more than 60 days ago, and is NOT of type directory, execute teh
    cygwin rm remove file command on it")



    Best Regards,
    --
    Todd H.
    http://www.toddh.net/

  10. Re: Batch File: Backup one file & add the date.

    Yes, but I strongly suggest you use something other than batch language
    for tasks such as these. Save the following to a file with a .vbs extension.

    set fso=createobject("scripting.filesystemobject")
    for i=1 to 8
    if isnumeric(mid(date,i,1)) then s=s & mid(date,i,1)
    next
    fso.copyfile "c:\editsdb.mdb","c:\backup\" & s & "editsdb.mdb"
    set f=fso.getfolder("c:\backup")
    set fc=f.files
    for each f1 in fc
    filedate=f1.datecreated
    if datevalue(left(dateadd("d",60,filedate),8))-date < 0 then
    answer=msgbox(f1.name & " is 60 days old. Delete it?",_
    vbyesno+vbquestion,"60 Days Old")
    if answer=vbyes then fso.deletefile("c:\backup\" & f1.name)
    end if
    next

    Ben

    "stevethrewup" wrote in message news:1130507590.901920.321370@f14g2000cwb.googlegr oups.com...
    > Is there also a way to delete the same file if it's more than 60 days
    > old?
    >
    > Thanks!
    >


+ Reply to Thread