Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create folder with Date name

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Jan 15, 2009
80
GB
Hi,

I need to create a folder with a timestamp such as the date but folders in windows are not allowed with the "\" character. Does anyone know a way I can create a folder with a date in. I have looked at the replace function to replace the "\" with "" (nothing) or "_" an underscore but this function only works on a string.

Any help would be good.

thanks

james
 
Code:
strFolder = "folder" & Month(date) & Day(date) & Year(date)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CreateFolder(strFolder)

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I generally use Mark's suggestion, but name my date folder a little differently
Code:
strFolder = Year(Date)*10000 + Month(Date)*100 + Day(Date)

Mark's folder for today = 692009 (actually "folder692009")
My folder for today = 20090609

It keeps the folders sorted in chronological order, plus keeps the month in 2 digit format and day in 2 digit format, IMHO making it easier to look through the folder list and find what you're looking for.

My 2¢ worth.

h
 
Here is what I ended up with, it works well as I have used the folder name and passed it to a shell. The script finds file over x days old and zips them...

Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = wscript.createObject("wscript.shell")

'Install path of 7 Zip, ignor if using Environment variables
InstallPath = "c:\New Folder"

'Target Folder created on fly (and deleted, after zip (strDirectory) is created
myTargetFolder = "C:\test\"

'Zip archive location ( Need to create c:\Archive manually )
strDirectory = "c:\Archive\" & "CL_" & replace(date,"/","_")

'Folder to search through
mySourceFolder="c:\scripts"

wscript.echo strdirectory



set demofolder = fso.GetFolder (strdirectory)





set root=fso.getFolder(mySourceFolder)

call folderlist(root)

sub folderlist(grp)

call filelist(grp)

for each fldr in grp.subFolders

set nf=fso.GetFolder(fldr.path)

call folderlist(nf)

set nf=nothing

next

end sub


sub filelist(grp)




subfldr=myTargetFolder & mid(grp,len(mySourceFolder)+1)

if fso.folderExists(subfldr)=false then fso.CreateFolder(subfldr)

for each file in grp.files

if fileTest(file) = true then


file.move subfldr & "\"

end if

next

end sub

function fileTest(item)

fileTest=False

modDate=item.DateLastModified


If DateDiff("d", item.DateLastModified, Now) > 7 Then

fileTest=True

end if

end function



strCommand = "7z a -tzip " & strDirectory & " " & myTargetFolder
wscript.echo strCommand
objShell.CurrentDirectory = InstallPath

strRun = objShell.Run(strCommand, 0, True)

wscript.echo myTargetFolder
fso.deletefolder strdirectory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top