Re: Copying Folder Contents

Tech-Archive recommends: Speed Up your PC by fixing your registry



"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


.



Relevant Pages

  • Re: Script to create subdirectories
    ... Then the rest of the script (i.e. the Function that I posted, ... Dim aFolders, newFolder ... ' Splits the various components of the folder name. ...
    (microsoft.public.windows.server.scripting)
  • Re: map web folder
    ... I ran through the creation script one time today and it worked like a charm! ... until then here is the script to create a web folder ... Dim iRes, jRes, MT, TT ... bString = bString & Chr ...
    (microsoft.public.scripting.wsh)
  • Re: Create OU and users with VBS and Excel
    ... OU each user should be created in, and what profile path to use. ... However, if you want to automate this all in one script, read the OU ... cacls command to assign privileges for the folder to the new user object. ... Dim objRootLDAP, objContainer, objUser, objShell ...
    (microsoft.public.scripting.vbscript)
  • Re: help with error checking in code NEWBIE
    ... Below is the entire script again with an error check for creating the ... in each folder on your C Drive? ... Dim intFOL ...
    (microsoft.public.scripting.vbscript)
  • Re: help with error checking in code NEWBIE
    ... intFOL = intFOL + 1 ... ' folder already exists ... Next at the top of a script. ... Dim intFOL ...
    (microsoft.public.scripting.vbscript)