Batch file for Autobackup

Page 1 of 2 12 LastLast

  1. Posts : 66
    XP Professional, 7 Professional
       #1

    Batch file for Autobackup


    I have a question regarding a batch file I've been working on to automate some of my daily tasks. I am copying a list of specific network database files from the server onto an external HD. Up until now I've just been manually Ctrl-clicking and dragging them over as a group. Not too difficult, but I thought it might be clever to handle it with an automated task.

    I've figured out how to COPY the files from one location to another, but I'm running into problems when I try and create a dated folder to drop them into. I understand that the "mkdir" command will make a file, and I was reading about how to have that file's name be "ddmmyy". My question is how do I write one code which creates the dated folder (preferably with dashes mm-dd-yy) and then copies the files into that newly created folder.

    Right now, my code has a static location to copy the files to. I need it to adapt to whatever the file name for that day is. I hope that makes sense.
      My Computer


  2. Posts : 6,668
    Windows 7 x64
       #2

    Code:
    @ECHO OFF
     FOR /F "tokens=1-4 delims=/ " %%I IN ('DATE /t') DO SET mydate=%%J%%K%%L 
    ECHO The value is "%mydate%"
    will create a value that is %mydate% and will always contain the current date (the format you want but no dashes)
    I don't know if this can be used in conjuction with the mkdir command in naming the folder though.

    mkdir just doesn't have any switches or variables associated with it.
    All it does is make directories.
    This is actually one command linux has win beat on
      My Computer


  3. Posts : 66
    XP Professional, 7 Professional
    Thread Starter
       #3

    Huzzah!!


    Even though your code wasn't exactly what I needed, it contained the missing puzzle piece. A light bulb went off in my head, and suddenly the world's simplest workaround was right in front of me. I use the "md" function to create a folder called "temp" then copy all the files to the static folder, then rename the folder to the current date using a function quite similar to yours. Here is the finished product, I've replaced all of the user specific information with descriptions in red parenthesis:

    @echo off
    md "(drive):\(path)\temp"
    COPY "(drive):\(path)\(filename1.type)" "(drive):\(path)\temp"
    COPY "(drive):\(path)\(filename2.type)" "(drive):\(path)\temp"
    COPY "(drive):\(path)\(filename3.type)" "(drive):\(path)\temp"
    COPY "(drive):\(path)\(filename4.type)" "(drive):\(path)\temp"
    COPY "(drive):\(path)\(filename5.type)" "(drive):\(path)\temp"
    COPY "(drive):\(path)\(filename6.type)" "(drive):\(path)\temp"
    COPY "(drive):\(path)\(filename7.type)" "(drive):\(path)\temp"
    for /f "tokens=1-4 delims=/ " %%d in ("%date%") do rename "(drive):\(path)\temp" %%e-%%f-%%g

    Works like a charm, saves me time, and makes me look like a computer whiz to my boss. Thanks to Maguscreed and Win7 forums as always. Every time I've posted here I've had nothing but good experiences.
      My Computer


  4. Posts : 6,668
    Windows 7 x64
       #4

    Nice, I figured that would push you in the right direction.
    Creative solution I was sitting there trying to figure out how to drop %mydate% info into mkdir.
    ...don't think it can be done that way at all though.
      My Computer


  5. Posts : 6,668
    Windows 7 x64
       #5

    You know I just had another thought about this.
    You could set up a autoplay on the usb drive so it automatically copies whenever you plug in the back device.
      My Computer


  6. Posts : 66
    XP Professional, 7 Professional
    Thread Starter
       #6

    True, I never thought of that, I'll try it today.

    **update**
    Didn't have much time to mess with this, but my initial attempts were unsuccessful. I created an autorun.inf file and placed it in the external drive. I thought the code would be a piece of cake, ([autorun] open=*), but no matter how I try and format the text, I get no result. The autorun definitely boots when I turn on the external, but the batch file doesn't run. I tried using shellexecute instead of open, but to no avail.

    I'm guessing it's because the .bat isn't an .exe. So maybe if I run a modified setup.exe, or some other intermediary program I'll have some more luck. Let me know what your take is, I'd be interested to know all my options before I troubleshoot further.

    Is it wrong that I find this terribly interesting? LoL
    Last edited by mjm6783; 19 Jul 2011 at 18:59.
      My Computer


  7. Posts : 66
    XP Professional, 7 Professional
    Thread Starter
       #7

    Hmmm.. a bunch of threads online are implying that autorun functions have been disabled for external drives. Not sure if I fully believe that or not. Can anyone confirm or deny?
      My Computer


  8. Posts : 66
    XP Professional, 7 Professional
    Thread Starter
       #8

    I don't seem to be able to run the batch file with an autoplay function, everywhere I look, people say that the code is super simple, and should look something like this:

    [autorun]
    open=filename.bat

    or

    [autorun]
    open=filepath\filename.bat

    I've also tried substituting "shell" and "shellexecute" for open. It's weird, because when I type the file path into "run" it works, and I thought the shellexecute function would work the same. When the autorun.inf file activiates, it pops up a flashlight and attempts to run something, but the batch never runs, and the files aren't copied.

    This isn't a huge deal, because I can just keep a copy of the .bat on my desktop and double click it once I've plugged the drive in. But now I'm seriously curious as to what steps I've missed here. Any help would be greatly appreciated.
      My Computer


  9. Posts : 6,668
    Windows 7 x64
       #9

    try this way

    Code:
    [AutoRun]
    OPEN=backup.bat
    ICON=MYAPP.EXE
    ACTION=Run Backup Routine
    just put any icon file on the usb root and change target to suit.
    I think that's what it's looking for.
      My Computer


  10. Posts : 66
    XP Professional, 7 Professional
    Thread Starter
       #10

    Still not working


    So, I've made some progress, but I'm still stumped. I'm starting to think that it has something to do with the drive itself. It's a Verbatim 500GB external desktop drive. It's formatted to NTSB. When I originally bought it, I had set it up to run as a multiboot drive, in order to run .ISO programs.

    In order to bypass the potential conflict between autorun and .bat files, I even tried creating a self extracting .exe, using IExpress.exe. When I double click the .exe it runs the .bat with no issues. But a simple autorun function to run the .exe gives no significant response.

    I tried your format, with both the .bat file, and the .exe file. It won't open with either. The autorun is functioning, because the icon I used replaced the default one. Also, it's searching the drive, (theoretically trying to find the file to open), but it never actually locates it. I'm checking the root path now, but to no avail. I feel like I'm missing a simple detail, but I've tried so many combinations, that it seems unlikely.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:23.
Find Us