INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- Turn Off Ad Banners
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Member Feedback
"...Your site has saved me hours of work that I cannot begin to express my satisfaction..."
Geography
Where in the world do Tek-Tips members come from?
|
dynamically create a folder andmove files into it
|
|
|
zephyran (TechnicalUser) |
26 Aug 03 17:14 |
Is there any way to write a script for Windows that will dynamically create a directory based on the date and time (while still following the naming rules of Windows), and then move all files from one directory into it?
I have tried creating such a script using VBScript:
Dim fso Dim fso1 Dim file1 Dim file2 Dim tday tday = Date Set fso = CreateObject("Scripting.FileSystemObject") Set file1 = fso.CreateFolder("\\server\homedir\testresults\" & tday) Set fso1 = CreateObject("Scripting.FileSystemObject") Set file2 = fso.MoveFile("\\server\homedir\admintest\*.*","\\server\homedir\testresults\" & tday)
Basically in this script I'm trying to create a folder inside the UNC path "\\server\homedir\testresults\" that is named the current date, and the move all files from "\\server\homedir\admintest\" into that directory.
I haven't programmed in JScript before, but if it has better capabilities for this than VBScript, I would gladly use it instead. Does anyone have any advice? |
|
|
palbano (Programmer) |
26 Aug 03 17:28 |
Break that down into smaller pieces to solve the problem. First you need to know what those string values are the you create right? >> "\\server\homedir\testresults\" & tday >> "\\server\homedir\testresults\" & tday Once you know those values try creating those file/folder names using Windows Explorer. If it can’t be done there you probably can’t do it from script right? So you have to format the date into a string that will work as a file/folder name right? So that is a totally separate piece Then try a script with a sample filename string hard coded rather than building it dynamically to make sure it works from script right? Then all that remains is to write the correct code to generate the dynamic string using the date formatting functions right? -pete
|
|
Backslash '\' is an escape character in JavaScript. When you're dealing with paths you'll need to escape your backslashes with other backslashes.
"\\server\homedir\testresults\" won't work, "\\\\server\\homedir\\testresults\\" will. |
|
should be able to use this: dim fso, folder1, folder2, tday
rem results in an ISO style date: YYYYMMDD tday = year(date()) & lz(month(date())) & lz(day(date()))
set fso = createObject("scripting.fileSystemObject")
set folder1 = fso.getFolder("\\server\homedir\admintest")
if fso.folderexists("\\server\homedir\testresults\" & tday) then set folder2 = fso.getFolder("\\server\homedir\testresults\" & tday) else set folder2 = fso.createFolder("\\server\homedir\testresults\" & tday) end if
rem copy all files in folder1 fso.copyFile folder1.path & "\*.*", folder2.path, true
rem copy all subfolders of folder1 & their contents fso.copyFolder folder1.path & "\*", folder2.path, true
function lz(byval i) if i < 10 then lz = "0" & i else lz = i end if end function ========================================================= -jeff www.jeffemminger.com try { succeed(); } catch(E) { tryAgain(); } |
|
|
zephyran (TechnicalUser) |
28 Aug 03 16:59 |
Forgive me, but I'm a Jscript virgin. What does the last part (function lz(byval i) and so on) do? |
|
actually, i wrote it all in vbscript. function lz adds a leading zero to numbers less than ten, so you always get a two digit number for months & days ========================================================= -jeff www.jeffemminger.com try { succeed(); } catch(E) { tryAgain(); } |
|
|
zephyran (TechnicalUser) |
29 Aug 03 12:03 |
Perfect, it's exactly what I needed! Thanks! |
|
|
 |
|
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close