-
Member
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?
-
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.
-
Member
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?
-
Member
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.
-
Member
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 + "\\");
-
Member
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.
-
Member
-
For VBscript, look up the DateFormat function.
-
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?
-
Member
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 + "\\");
-
Wow thanks worked great.
Takes less than a sec to backup a entire 20 MB Website.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks