Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: File copy error

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: File copy error
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: File copy error - 1/4/2007 8:26:45 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
In that case, I don't understand why you do this:

osourcename = str&str1&str2&str3&".bak"

The name of the file is the same in the source directory and the destination directory?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Raknahs)
 
 
Post #: 21
 
 RE: File copy error - 1/4/2007 10:01:59 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
In the source folder I have different type of .bak files.

for ex.  I have

lcms_backup_200611011903.bak
lcms_backup_200611021902.bak
lcms_backup_200611021902.bak

master_backup_200610261902.bak
master_backup_200610271901.bak
master_backup_200610301901.bak

model_backup_200611271903.bak
model_backup_200611282133.bak
model_backup_200612012134.bak

msdb_backup_200611241903.bak
msdb_backup_200611261903.bak
msdb_backup_200611271703.bak


These are all the types of files creating automatically by the system  in production server. I need to back up only the specific file to the backup server i.e. destination folder for ex.  I want to backup only the file starts with

lcms_200611271903.bak  & model_backup_200612112133.bak   to the destination folder (i.e. backup server)

I dont want to copy the files other than that. Thats why i am using the specific file osourcename = str&str1&str2&str3&".bak"

These file creates automatically daily  in the production server.  Only the specific file which i mentioned has to get copied into the destination folder (backup server). If any specific files which i mentioned is deleted from the source folder, the same has to be deleted from the destination folder immediately by verifying the files stored in the destination folder. This is what exactly i need from the script.

If you have anyfurther clarification pls. let me know i can explain you clearly.


Thanks
Raknahs




(in reply to ebgreen)
 
 
Post #: 22
 
 RE: File copy error - 1/5/2007 2:25:57 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
See if this works for you:


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Raknahs)
 
 
Post #: 23
 
 RE: File copy error - 1/5/2007 4:33:09 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
Hi Thanks for your help, I tried to execute the code which has been given by you, I got an error in the line 28 (highlighted in Bold)

Error - File Not found,  The network path was not found. Any advice.


Option Explicit
Dim oFSO
Dim strSrc
Dim strDest

Set oFSO = CreateObject("Scripting.FileSystemObject")
strSrc = "c:\sourcetest\"
strDest = "c:\test_dst\"
ReplicateFiles oFSO, strSrc, strDest
PurgeArchive oFSO, strSrc, strDest
Sub ReplicateFiles(oFSO, strSrcFolder, strDestFolder)
Dim oFile
Dim strNewName
Dim bDoCopy

'Iterate through each of the files in the source dir
For Each oFile In oFSO.GetFolder(strSrcFolder).Files
     'See if the file needs to be renamed
     strNewName = strDestFolder & "\" & oFile.Name - {can u advice why do u use the line}
      bDoCopy = False
     'Only copy the file if it is lcms_ or master_
     If Left(oFile.Name, 5) = "lcms_" Or Left(oFile.Name, 7) = "master_" Then
         bDoCopy = True
         'See if the file already exists and the mod date is different
          If oFSO.FileExists(strNewName) And oFile.DateLastModified = oFSO.GetFile(strNewName).DateLastModified Then - {Error - File not found, the network path was not found}
              bDoCopy = False
         End If
     End If
     If bDoCopy Then
         oFile.Copy strNewName, True
     End If
Next

End Sub
Sub PurgeArchive(oFSO, strSrcFolder, strDestFolder)
  Dim oFile
 
  Check each file in the dest directory to see if there is a matching file in source
  For Each oFile In oFSO.GetFolder(strDestFolder).Files
      If Not oFSO.FileExists(strSrcFolder & "\" & oFile.Name) Then
          oFile.Delete(True)
      End If
  Next
 
End Sub

Thanks
Raknahs

(in reply to ebgreen)
 
 
Post #: 24
 
 RE: File copy error - 1/5/2007 4:46:44 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Option Explicit
Dim oFSO
Dim strSrc
Dim strDest

Set oFSO = CreateObject("Scripting.FileSystemObject")
strSrc = "c:\sourcetest\"
strDest = "c:\test_dst\"
ReplicateFiles oFSO, strSrc, strDest
PurgeArchive oFSO, strSrc, strDest
Sub ReplicateFiles(oFSO, strSrcFolder, strDestFolder)
Dim oFile
Dim strNewName
Dim bDoCopy

'Iterate through each of the files in the source dir
For Each oFile In oFSO.GetFolder(strSrcFolder).Files
     'See if the file needs to be renamed
     strNewName = strDestFolder & oFile.Name - {can u advice why do u use the line}  - Because the name is simply the name of the file. To copy it we need the path too. I didn't see the \ in the path already so I have now taken it out.
      bDoCopy = False
     'Only copy the file if it is lcms_ or master_
     If Left(oFile.Name, 5) = "lcms_" Or Left(oFile.Name, 7) = "master_" Then
         bDoCopy = True
         'See if the file already exists and the mod date is different
         On Error Resume Next
          If oFSO.FileExists(strNewName) And oFile.DateLastModified = oFSO.GetFile(strNewName).DateLastModified Then - {Error - File not found, the network path was not found}
              bDoCopy = False
         End If
        On Error Goto 0
     End If
     If bDoCopy Then
         oFile.Copy strNewName, True
     End If
Next

End Sub
Sub PurgeArchive(oFSO, strSrcFolder, strDestFolder)
  Dim oFile
 
  Check each file in the dest directory to see if there is a matching file in source
  For Each oFile In oFSO.GetFolder(strDestFolder).Files
      If Not oFSO.FileExists(strSrcFolder & "\" & oFile.Name) Then
          oFile.Delete(True)
      End If
  Next
 
End Sub

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Raknahs)
 
 
Post #: 25
 
 RE: File copy error - 1/5/2007 6:33:48 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
Hi,

I just tried with the modified code, Purging is working, copying the files from the source folder to the destination folder doesn't work. I wont get any error, while at the time of executing the code, may be due to on error resume next. When i remove the onerror resume next. I got a  error which happened earlier, the path is not found.  If it works properly then my work gets done. Can u pls. advice for the final solution.








Thanks
Raknahs

(in reply to ebgreen)
 
 
Post #: 26
 
 RE: File copy error - 1/5/2007 6:37:54 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Try this code. Run it from a command line because it will potentially produce a lot of output.

Option Explicit
Dim oFSO
Dim strSrc
Dim strDest

Set oFSO = CreateObject("Scripting.FileSystemObject")
strSrc = "c:\sourcetest\"
strDest = "c:\test_dst\"
ReplicateFiles oFSO, strSrc, strDest
PurgeArchive oFSO, strSrc, strDest
Sub ReplicateFiles(oFSO, strSrcFolder, strDestFolder)
Dim oFile
Dim strNewName
Dim bDoCopy

'Iterate through each of the files in the source dir
For Each oFile In oFSO.GetFolder(strSrcFolder).Files
     'See if the file needs to be renamed
     strNewName = strDestFolder & oFile.Name
    WScript.Echo "Checking: " & strNewName
      bDoCopy = False
     'Only copy the file if it is lcms_ or master_
     If Left(oFile.Name, 5) = "lcms_" Or Left(oFile.Name, 7) = "master_" Then
         bDoCopy = True
         'See if the file already exists and the mod date is different
         On Error Resume Next
          If oFSO.FileExists(strNewName) Then
          If oFile.DateLastModified = oFSO.GetFile(strNewName).DateLastModified Then
                bDoCopy = False
          End If
         End If
        On Error Goto 0
     End If
     If bDoCopy Then
         oFile.Copy strNewName, True
     End If
Next

End Sub
Sub PurgeArchive(oFSO, strSrcFolder, strDestFolder)
  Dim oFile
 
  Check each file in the dest directory to see if there is a matching file in source
  For Each oFile In oFSO.GetFolder(strDestFolder).Files
      If Not oFSO.FileExists(strSrcFolder & "\" & oFile.Name) Then
          oFile.Delete(True)
      End If
  Next
 
End Sub

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Raknahs)
 
 
Post #: 27
 
 RE: File copy error - 1/5/2007 7:09:31 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
It seems to be to be working Perfect. , Your work is really appreciated.


Thanks a lot for your help.




Thanks
Raknahs

(in reply to ebgreen)
 
 
Post #: 28
 
 RE: File copy error - 1/8/2007 3:48:23 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
Hi,

I have Implemented the script in the production it works good, Now, we planned to backup the specific file, lcms and Rightfax,. Earlier we used the file lcms and master,  I tried to change only the file in the line which is highlighted in bold word, I modified it into Rightfax and specified the size has 9. When i execute the script, it is not copying the rightfax file.

When i used the master filename instead of right fax, Its working perfect. Can u pls. advice, why do i have the problem.



Option Explicit
Dim oFSO
Dim strSrc
Dim strDest
Set oFSO = CreateObject("Scripting.FileSystemObject")
strSrc = "C:\sourcetest\"
strDest = "c:\test_dst\"
ReplicateFiles oFSO, strSrc, strDest
PurgeArchive oFSO, strSrc, strDest
Sub ReplicateFiles(oFSO, strSrcFolder, strDestFolder)
Dim oFile
Dim strNewName
Dim bDoCopy
'Iterate through each of the files in the source dir
For Each oFile In oFSO.GetFolder(strSrcFolder).Files
    'See if the file needs to be renamed
    strNewName = strDestFolder & oFile.Name
   WScript.Echo "Checking: " & strNewName
     bDoCopy = False
    'Only copy the file if it is lcms_ or Rightfax_
     If Left(oFile.Name, 5) = "lcms_" Or Left(oFile.Name, 9) = "RightFax_" Then
         bDoCopy = True
        'See if the file already exists and the mod date is different
        On Error Resume Next
         If oFSO.FileExists(strNewName) Then
         If oFile.DateLastModified = oFSO.GetFile(strNewName).DateLastModified Then
               bDoCopy = False
         End If
        End If
       On Error Goto 0
    End If
    If bDoCopy Then
        oFile.Copy strNewName, True
    End If
Next
End Sub
Sub PurgeArchive(oFSO, strSrcFolder, strDestFolder)
Dim oFile

'Check each file in the dest directory to see if there is a matching file in source
For Each oFile In oFSO.GetFolder(strDestFolder).Files
     If Not oFSO.FileExists(strSrcFolder & "\" & oFile.Name) Then
         oFile.Delete(True)
     End If
Next
End Sub


(in reply to Raknahs)
 
 
Post #: 29
 
 RE: File copy error - 1/8/2007 4:00:58 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well, is the file name RightFax_ or rightfax_? To be honest with you, that line isn't really as robust as it should be. Try changing this:

If Left(oFile.Name, 5) = "lcms_" Or Left(oFile.Name, 9) = "RightFax_" Then

To be:

If UCase(Left(oFile.Name, 5)) = UCase("lcms_") Or UCase(Left(oFile.Name, 9)) = UCase("RightFax_") Then

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Raknahs)
 
 
Post #: 30
 
 RE: File copy error - 1/8/2007 6:21:51 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
Hi,

Thanks for your advice, I tried with the existing code, It works after a long time. Issue being solved.









Thanks
Raknahs

(in reply to ebgreen)
 
 
Post #: 31
 
 
Page:  <<   < prev  1 [2]
 
  

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 >> RE: File copy error Page: <<   < prev  1 [2]
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