INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

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!

E-mail*
Handle

Password
Verify P'word
*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
Partner Button
(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?
Check Out Our Whitepaper Library. Click Here.
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

dwarfthrower (Programmer)
26 Aug 03 17:37
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.
Helpful Member!jemminger (Programmer)
26 Aug 03 18:10
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?
Helpful Member!jemminger (Programmer)
28 Aug 03 17:39
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!

Start A New Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Promoting, selling, recruiting and student posting
are not allowed in the forums.
Posting Policies

LINK TO THIS FORUM!
(Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum)
TITLE: Javascript Forum at Tek-Tips
URL: http://www.tek-tips.com/threadminder.cfm?pid=216
DESCRIPTION: Javascript technical support forum and mutual help system for computer professionals. Selling and recruiting forbidden.

 

Back To Forum

Close Box

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close