Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
|
|