Re: Copying Folder Contents
- From: "Bradley" <bradley@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 19 Aug 2005 11:18:57 +0100
"McKirahan" <News@xxxxxxxxxxxxx> wrote in message
news:s6ydncgAONMj1JjeRVn-qg@xxxxxxxxxxxxxx
> "Bradley" <bradley@xxxxxxxxxxxxxxxxxx> wrote in message
> news:#8MVHbEpFHA.2916@xxxxxxxxxxxxxxxxxxxxxxx
>> Hi
>>
>> I haven't the slightest idea about scripts, I have been trying to write a
>> batch file to do the job, with no success and I have been informed that a
>> script is what I need.
>>
>> Here is my predicament:
>> This action needs to work in an NT and XP environment
>>
>> I need to move files at the end of ever month stored in 2 different
> folders,
>> to a backup location.
>> For example this is where the files are located:
>> p:\cmanger\{Workstation_name}\Dailydoc
>> p:\cmanger\{Workstation_name}\DailyImg
>
>>
>> I would like all the files within the 2 folders all moved to
>> p:\cmanger\backup\DailyDoc & p:\cmanger\backup\DailyImg
>> Which should then leave the original file locations empty.
>>
>> However each workstation I need to perform the action on has a different
>> folder name in the middle.
>> It's always the workstation name, if this helps?
>>
>> Is it possible to write a script to automatically perform this action at
> the
>> end of each month.
>> If so, would it also be possible to move them to a folder of the time
> period
>> i.e. named "yyyymmdd" each time the script runs.
>>
>> Your expert help on this would be most appreciated.
>>
>> Regards,
>>
>> Bradley
>>
>>
>
>
> Will this work for you? Watch for word-wrap.
>
> It also appends a line to a log file.
>
> You can use the Windows Task Scheduler to run it at EOM.
>
>
> Option Explicit
> '*
> '* Declare Constants
> '*
> Const cVBS = "pcmanger.vbs"
> Const cLOG = "pcmanger.log"
> Const cFR1 = "p:\cmanger\?\Dailydoc"
> Const cFR2 = "p:\cmanger\?\DailyImg"
> Const cTO1 = "p:\cmanger\backup\DailyDoc\?"
> Const cTO2 = "p:\cmanger\backup\DailyImg\?"
> Const cWSS = "COMPUTERNAME"
> '*
> '* Declare Variables
> '*
> Dim strFR1 '= FROM folder #1
> Dim strFR2 '= FROM folder #2
> Dim strMSG '= Message
> Dim strNOW '= Current Date+Time
> strNOW = Now
> Dim strSFN '= Script Full Name's Folder
> strSFN = WScript.ScriptFullName
> strSFN = Left(strSFN,InStrRev(strSFN,"\"))
> Dim strTO1 '= TO folder #1
> Dim strTO2 '= TO folder #2
> Dim strWKS '= Workstation
> Dim strWSS '= Environment
> Dim strYMD '= YYYYMMDD
> strYMD = DatePart("yyyy",strNOW)
> strYMD = strYMD & Right(100+DatePart("m",strNOW),2)
> strYMD = strYMD & Right(100+DatePart("d",strNOW),2)
> '*
> '* Declare Objects
> '*
> Dim objFSO
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Dim objOTF
> Set objOTF = objFSO.OpenTextFile(strSFN & cLOG,8,True)
> Dim objWSS
> Set objWSS = CreateObject("WScript.Shell")
> '*
> '* Workstation Name (e.g. "COMPUTERNAME=ABC123" )
> '*
> For Each strWSS in objWSS.Environment("Process")
> If Left(strWSS,Len(cWSS)) = cWSS Then
> strWKS = Mid(strWSS,Len(cWSS)+2)
> End If
> Next
> strFR1 = Replace(cFR1,"?",strWKS)
> strFR2 = Replace(cFR2,"?",strWKS)
> strTO1 = Replace(cTO1,"?",strYMD)
> strTO2 = Replace(cTO2,"?",strYMD)
> strMSG = strWKS & " = "
> '*
> '* Copy Files (w/ overwrite) the Delete Files
> '*
> If objFSO.FolderExists(strFR1) _
> And objFSO.FolderExists(strFR2) _
> And Not objFSO.FolderExists(strTO1) _
> And Not objFSO.FolderExists(strTO2) Then
> objFSO.CreateFolder strTO1
> objFSO.CopyFile strFR1 & "\*.*", strTO1, True
> objFSO.DeleteFile strFR1 & "\*.*", True
> objFSO.CreateFolder strTO2
> objFSO.CopyFile strFR2 & "\*.*", strTO2, True
> objFSO.DeleteFile strFR2 & "\*.*", True
> strMSG = "Successful!"
> Else
> strMSG = "Failed!"
> End If
> objOTF.WriteLine(strNOW & " : " & strWKS & " = " & strMSG)
> '*
> '* Destroy Objects
> '*
> Set objFSO = Nothing
> Set objOTF = Nothing
> Set objWSS = Nothing
> '*
> '* Display Message
> '*
> MsgBox strMSG,VBInformation,cVBS
>
>
Hi McKirahan
That's amazing, I haven't a clue what it all means, but it creates a log
file error
19/08/2005 11:11:09 : STUDY = Failed!
Am I supposed to change something
Regards
Bradley
.
- Follow-Ups:
- Re: Copying Folder Contents
- From: McKirahan
- Re: Copying Folder Contents
- References:
- Copying Folder Contents
- From: Bradley
- Re: Copying Folder Contents
- From: McKirahan
- Copying Folder Contents
- Prev by Date: Re: wscript.exec in hidden window?
- Next by Date: Re: reading through a text file checking the first character on each line
- Previous by thread: Re: Copying Folder Contents
- Next by thread: Re: Copying Folder Contents
- Index(es):
Relevant Pages
|