Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Create Folder with Todays Date then Copy Data to it

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,52070
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create Folder with Todays Date then Copy Data to it
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Create Folder with Todays Date then Copy Data to it - 9/20/2007 6:56:44 AM   
  svansingel

 

Posts: 11
Score: 0
Joined: 9/18/2007
Status: offline
HELP.
I have a scirpt that wil creat a folder with todays date.
Done.
now I need to copy files to it.
How do you write a script to do this.

If I set the string as this: it will create the folder  c:\apacs\date\pslogs

strFolderName = "C:\APACS\" & strCompName & "_" & strMonth & "-" & strDay & "-" & strYear
PSLogsFolder = (strFolderName) & "\PSLogs"
APILogsFolder = (strFolderName) & "\APIlogs"
msgBox PSLogsFolder
msgBox APILogsFolder

Now if I need to copy files from one folder to the newly created folder. How do you call it.
I have this so far
objFSO.CopyFile "SourceComputer", strPSLogsFolder, OverwriteExisting  
the files will not copy to the new folder. Please help
 
 
Post #: 1
 
 RE: Create Folder with Todays Date then Copy Data to it - 9/20/2007 4:05:55 PM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
unless you didn't post your entire script your missing the first line.  this works fine... well at least for me...

Const OverWriteFiles = True
Source = "C:\test1"
Destination = "C:\test2"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder Source, Destination, OverWriteFiles

< Message edited by sheepz -- 9/20/2007 4:09:05 PM >

(in reply to svansingel)
 
 
Post #: 2
 
 RE: Create Folder with Todays Date then Copy Data to it - 9/20/2007 11:07:01 PM   
  svansingel

 

Posts: 11
Score: 0
Joined: 9/18/2007
Status: offline
OK below is the entire script.
It does create the folders.
The msg box shows the correct path, however the files are not being copied to the folder
If you look at the objFSO.CopyFile "\\" &strComputer &"\c$\Documents and Settings\" &strNewComp &"\Local Settings\Application Data\Dictaphone\HSG\Trace\PSClientApp\PSClientApp_LOG.txt", strPSLogsFolder, OverwriteExisting  

it would copy the files if I put something like C:\FOlderName
However since the script above created a new folder with todays date, I need the data to be copied to the new folder.
So, in the CopyFile line, I used the StrPsLogsFolder string.
I just can not seem to get the data copied to the folder.

HELP
Thanks in advance.



' VBScript source code
Dim strComputer
Dim objWMIService
Dim objComputer, colComputer
Dim thisComp, strNewComp
Dim objFSO
Dim disFSO, disFolder

strComputer = "pacs-wks2"
strMonth = Month(Date)
If Len(strMonth) = 1 Then
   strMonth = "0" & strMonth
End If
  strDay = Day(Date)
  If Len(strDay) = 1 Then
  strDay = "0" & strDay
End If
strYear = Year(Date)
strCompName = REPLACE(strComputer,"egh-pacs-","")
strFolderName = "C:\APACS\" & strCompName & "_" & strMonth & "-" & strDay & "-" & strYear
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strFolderName)
objFSO.CreateFolder(strFolderName) & "\PSLogs"
objFSO.CreateFolder(strFolderName) & "\APIlogs"
PSLogsFolder = (strFolderName) & "\PSLogs"
APILogsFolder = (strFolderName) & "\APIlogs"
msgBox PSLogsFolder
msgBox APILogsFolder

Call copythisFile()
Call copythatFile()

Sub copythisFile()
on error resume next
Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
     ("Select * from Win32_ComputerSystem")
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each objComputer in colComputer
     thisComp = objComputer.UserName
     strNewComp = REPLACE(thisComp,"EGH\","")
     'wscript.echo strNewComp
     datstr = "\\" &strComputer &"\" &"%" &strNewComp &"%" &"\Local Settings\Application Data\Dictaphone\HSG\Trace\PSClientApp\PSClientApp_LOG.txt"
     'wscript.echo datstr
  msgBox strNewComp
  msgBox PSLogsFolder
  msgBox APILogsFolder
  wscript.Sleep 6000
     objFSO.CopyFile "\\" &strComputer &"\c$\Documents and Settings\" &strNewComp &"\Local Settings\Application Data\Dictaphone\HSG\Trace\PSClientApp\PSClientApp_LOG.txt", strPSLogsFolder, OverwriteExisting  
Next

End Sub


Sub copyThatFile()
  strPath= "\\" & strComputer & "\c$\ali\site\log"
  Const OverwriteExisting = True
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFSO.GetFolder(strPath)
  set colFiles = objFolder.files
  mytime = Date

 
  For Each file in ColFiles
    on Error resume next
thisExt = file.Name
    If file.datelastmodified >= myTime and Instr(thisExt,"log") Then
      objFSO.CopyFile File , APILogsFolder , OverwriteExisting
  'Else Wscript.Echo "False!"
    End If

  Next
  wscript.echo "Transfer Complete"
End Sub

Set strComputer = Nothing
Set objWMIService = Nothing
Set objComputer = Nothing
set objFSO = Nothing
set disFSO = Nothing

(in reply to svansingel)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create Folder with Todays Date then Copy Data to it Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts