Hi,
I'm trying to write a vbscript that, when run, will create a new folder
with a unique timestamp and move the files in one folder, into the new
folder. I keep getting an error when I run the script and I can't
figure out why... if anyone can have a look it would be greatly
appreciated!
Thanks in advance,
MJ

Option Explicit

' Create the File System Object
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim errorFolder
errorFolder = "C:\errors"

Dim ef
Set ef = FSO.GetFolder(errorFolder)


''''''''''''''''''''''''''''''''''''''
'Create Unique Destination Folder
''''''''''''''''''''''''''''''''''''''
Dim datetoday, timetoday
Dim strMonth, strDay, strHour, strMinute, strSecond
Dim strDirectory
datetoday = now
strMonth = Month(datetoday)
strDay = Day(datetoday)
strHour = Hour(datetoday)
strMinute = Minute(datetoday)
strSecond = Second(datetoday)
if len(strMonth) = 1 then
strMonth = "0" & strMonth
end if
if len(strDay) = 1 then
strDay = "0" & strDay
end if
if len(strHour) = 1 then
strHour = "0" & strHour
end if
if len(strMinute) = 1 then
strMinute = "0" & strMinute
end if
if len(strSecond) = 1 then
strSecond = "0" & strSecond
end if
datetoday = YEAR(datetoday) & strMonth & strDay
timetoday = strHour & strMinute & strSecond
strDirectory = "c:\archive\" & datetoday & "_" & timetoday
FSO.CreateFolder(strDirectory)


Dim f

For Each f in ef.Files

' Copy the file to the archive folder

FSO.MoveFile f, strDirectory

Next

Re: Newbie - moving files to another folder by Michael

Michael
Wed Nov 08 21:27:10 CST 2006

MJ wrote:
> Hi,
> I'm trying to write a vbscript that, when run, will create a new
> folder with a unique timestamp and move the files in one folder, into
> the new folder. I keep getting an error when I run the script and I
> can't figure out why... if anyone can have a look it would be greatly
> appreciated!
> Thanks in advance,
> MJ
>
> Option Explicit
>
> ' Create the File System Object
> Dim FSO
> Set FSO = CreateObject("Scripting.FileSystemObject")
>
> Dim errorFolder
> errorFolder = "C:\errors"
>
> Dim ef
> Set ef = FSO.GetFolder(errorFolder)
>
>
> ''''''''''''''''''''''''''''''''''''''
> 'Create Unique Destination Folder
> ''''''''''''''''''''''''''''''''''''''
> Dim datetoday, timetoday
> Dim strMonth, strDay, strHour, strMinute, strSecond
> Dim strDirectory
> datetoday = now
> strMonth = Month(datetoday)
> strDay = Day(datetoday)
> strHour = Hour(datetoday)
> strMinute = Minute(datetoday)
> strSecond = Second(datetoday)
> if len(strMonth) = 1 then
> strMonth = "0" & strMonth
> end if
> if len(strDay) = 1 then
> strDay = "0" & strDay
> end if
> if len(strHour) = 1 then
> strHour = "0" & strHour
> end if
> if len(strMinute) = 1 then
> strMinute = "0" & strMinute
> end if
> if len(strSecond) = 1 then
> strSecond = "0" & strSecond
> end if
> datetoday = YEAR(datetoday) & strMonth & strDay
> timetoday = strHour & strMinute & strSecond
> strDirectory = "c:\archive\" & datetoday & "_" & timetoday
> FSO.CreateFolder(strDirectory)
>
>
> Dim f
>
> For Each f in ef.Files
>
> ' Copy the file to the archive folder
>
> FSO.MoveFile f, strDirectory

'make sure the destination has a trailing "\"
'so that it is not ambiguous to the MoveFile method...
'
FSO.MoveFile f, strDirectory & "\"



>
> Next

--
Michael Harris
Microsoft MVP Scripting