+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Member Undeadlord's Avatar
    Join Date
    Mar 2001
    Location
    Washington DC
    Posts
    225

    Writing a batch file

    Hey guys,

    I have a question. I need to write a batch file that will run under Task Scheduler. I need it to get the time, make a directory with the name of the current time and move a file to that dir. Now the making a directing and copying a folder I can do. But how do I get the time and make the time th dir name? I think this would be done in Win98 .. but maybe WIn2k? .... SO could this be done at all and in both OS's? Thanks for your help.


    Undeadlord

    Edit: Spelled my own name wrong!!!
    Undeadlord
    ----------------
    What undead do you want to control today?


  2. #2
    Member
    Join Date
    Jan 2001
    Location
    Bellevue, WA
    Posts
    78
    Unfortunately, I don't believe that you can, with the built in functions of DOS (Batch files specifically) make a folder based on the current time. You might ask Microsoft this question, but I know of no command to do this. You might be able to write some sort of VB or C++ app to do this, but I'm not sure how.
    -Digital D.

  3. #3
    Member Undeadlord's Avatar
    Join Date
    Mar 2001
    Location
    Washington DC
    Posts
    225
    Well does anyone know how to write a small c++ that can do what I need?

    Undeadlord
    Undeadlord
    ----------------
    What undead do you want to control today?


  4. #4
    Member strangerstill's Avatar
    Join Date
    Sep 2001
    Location
    Oxford
    Posts
    203
    Just use Windows Scipting Host (vbs or js)
    It superseded batch files years ago

    http://www.microsoft.com/msdn/scripting

    VBScript:

    Dim fso, newFolderPath
    Set fso = CreateObject("Scripting.FileSystemObject")
    newFolderPath = Now
    While Instr(newFolderPath, "/")
    newFolderPath = Left(newFolderPath, Instr(newFolderPath, "/")-1) & "." & Mid(newFolderPath, Instr(newFolderPath, "/")+1)
    Wend
    While Instr(newFolderPath, ":")
    newFolderPath = Left(newFolderPath, Instr(newFolderPath, ":")-1) & "." & Mid(newFolderPath, Instr(newFolderPath, ":")+1)
    Wend
    newFolderPath = "C:\" & newFolderPath
    fso.CreateFolder(newFolderPath)
    fso.CopyFile "c:\windows\tips.txt", newFolderPath & "\"
    Last edited by strangerstill; 09-22-2001 at 02:52 PM.

  5. #5
    Member strangerstill's Avatar
    Join Date
    Sep 2001
    Location
    Oxford
    Posts
    203
    Oh yeah, here's the JScript version:

    JScript:

    var fso;
    var newFolderPath;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    newFolderPath = "C:\\" + ((String)(new Date())).replace(/\//g, ".").replace(/:/g, ".");
    fso.CreateFolder(newFolderPath);
    fso.CopyFile("c:\\windows\\tips.txt", newFolderPath + "\\");

  6. #6
    Member strangerstill's Avatar
    Join Date
    Sep 2001
    Location
    Oxford
    Posts
    203
    Ooh. Note that the two scripts have different output. The .vbs gives

    C:\22.09.01 19.49.54\

    while the .js gives

    C:\Sat Sep 22 19.49.54 UTC +0100 2001\

    This is default behaviour but I guess consistency is possible; however I would recommend choosing one script and sticking to it.

  7. #7
    Member strangerstill's Avatar
    Join Date
    Sep 2001
    Location
    Oxford
    Posts
    203
    Sorry. That should be
    http://msdn.microsoft.com/scripting/

  8. #8
    Member
    Join Date
    Jan 2001
    Location
    Bellevue, WA
    Posts
    78
    For VBscript, look up the DateFormat function.
    -Digital D.

  9. #9
    Member
    Join Date
    Feb 2001
    Location
    Alabama
    Posts
    301
    This Would help me a good bit if I could copy a folder and lots of sub-directorys every few days. How Can I get this to copy the sub-directorys to?

  10. #10
    Member strangerstill's Avatar
    Join Date
    Sep 2001
    Location
    Oxford
    Posts
    203
    Easy: just use the CopyFolder method of the FileSystemObject object in place of the CopyFile method.

    So the line would be

    fso.CopyFile "c:\windows\samples\*", newFolderPath & "\"

    or

    fso.CopyFile("c:\\windows\\samples\\*", newFolderPath + "\\");

  11. #11
    Member
    Join Date
    Feb 2001
    Location
    Alabama
    Posts
    301
    Wow thanks worked great.
    Takes less than a sec to backup a entire 20 MB Website.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts







New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke