Login | |
|
 |
File copy error - 1/3/2007 6:18:24 AM
|
|
 |
|
| |
Raknahs
Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
|
Hi, Can any one help me out, what is the error in this script, When I am executing the script I got an error " Object required osourcename " in line 59 and 61. Highlighted in the bold font. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = wscript.CreateObject("wscript.network") SOURCE_FOLDER = "c:\sourcetest\" DESTINATION_FOLDER = "c:\test_dst\" ReplicateFiles objFSO, SOURCE_FOLDER, DESTINATION_FOLDER Sub ReplicateFiles (objFSO, strSourcefolderpath, strDestinationfolderpath) Dim aSourceFilearray Dim aDestinationfilearray Dim Sourcefilelist Dim Destinationfilelist Dim oFileSource Dim oFileDestination Dim bSourceExists Dim bDestinationExists dim osourcename 'On Error Resume Next Set aSourceFilearray = objFSO.GetFolder(strSourcefolderpath) Set Sourcefilelist = aSourceFilearray.Files Set aFileArrayDestination = objFSO.GetFolder(strDestinationfolderpath) Set FileListDestination = aFileArrayDestination.Files For each oFileSource in Sourcefilelist str1= Mid(oFileSource,15,12) str2 = Mid(oFileSource,27,8) str3 = Mid(oFileSource,35,4) If str1 = "lcms_backup_" then osourcename = str1&str2&str3&".bak" End If For each oFileDestination in FileListDestination bDestinationExists = 0 If osourcename.Name = oFileDestination.Name then If osourcename.DateLastModified = oFileDestination.DateLastModified Then bDestinationExists = 1 Exit For End If End If Next If bDestinationExists = 0 then osourcename.Copy strDestinationfolderpath & "\" & osourcename.Name MsgBox "copied" End If Next End Sub Thanks Raknahs
|
|
| |
|
|
|
 |
RE: File copy error - 1/3/2007 6:40:25 AM
|
|
 |
|
| |
dm_4ever
Posts: 2637
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
A quick look at this, your issue may be the following line osourcename = str1&str2&str3&".bak" and then trying to get the name & datelastmodified. You need to get the file using the FileSystemObject before you try to do a .name and .datelastmodified. i.e. osourcename = objFSO.GetFile(filespec) osourcename.name osourcename.datelastmodified
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: File copy error - 1/3/2007 7:05:25 AM
|
|
 |
|
| |
Raknahs
Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
|
Hi, Thanks for your reply, I just modified the script adviced by you. Still i have the problem furnishing the script Pls. advice. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = wscript.CreateObject("wscript.network") SOURCE_FOLDER = "c:\sourcetest\" DESTINATION_FOLDER = "c:\test_dst\" ReplicateFiles objFSO, SOURCE_FOLDER, DESTINATION_FOLDER Sub ReplicateFiles (objFSO, strSourcefolderpath, strDestinationfolderpath) Dim aSourceFilearray Dim aDestinationfilearray Dim Sourcefilelist Dim Destinationfilelist Dim oFileSource Dim oFileDestination Dim bSourceExists Dim bDestinationExists Dim osourcename 'On Error Resume Next Set aSourceFilearray = objFSO.GetFolder(strSourcefolderpath) Set Sourcefilelist = aSourceFilearray.Files Set aFileArrayDestination = objFSO.GetFolder(strDestinationfolderpath) Set FileListDestination = aFileArrayDestination.Files For each oFileSource in Sourcefilelist str1= Mid(oFileSource,15,12) str2 = Mid(oFileSource,27,8) str3 = Mid(oFileSource,35,4) If str1 = "lcms_backup_" then osourcename = str1&str2&str3&".bak" filespec = osourcename & Datelastmodified End If For each oFileDestination in FileListDestination bDestinationExists = 0 osourcename = objfso.GetFile(filespec) If osourcename.name = oFileDestination.Name then If osourcename.DateLastModified = oFileDestination.DateLastModified Then bDestinationExists = 1 Exit For End If End If Next If bDestinationExists = 0 then osourcename.Copy strDestinationfolderpath & "\" & osourcename.Name MsgBox "copy" End If Next End Sub Thanks Raknahs
|
|
| |
|
|
|
 |
RE: File copy error - 1/3/2007 8:14:03 AM
|
|
 |
|
| |
Raknahs
Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
|
Hi, Thanks for ur reply. I cant understand the variable you defined for Dim sFSpec : sFSpec = "FullFilespecOfSourcefile" I just modified the script based on your info. I got an error which is highlighted in bold word Error : "File Not found The network path was not found" Can u pls. advice why i am getting this error. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = wscript.CreateObject("wscript.network") SOURCE_FOLDER = "c:\sourcetest\" DESTINATION_FOLDER = "c:\test_dst\" ReplicateFiles objFSO, SOURCE_FOLDER, DESTINATION_FOLDER Sub ReplicateFiles (objFSO, strSourcefolderpath, strDestinationfolderpath) Dim aSourceFilearray Dim aDestinationfilearray Dim Sourcefilelist Dim Destinationfilelist Dim oFileSource Dim oFileDestination Dim bSourceExists Dim bDestinationExists Dim osourcename Dim sFSpec Dim oFile Dim sFileName 'On Error Resume Next Set aSourceFilearray = objFSO.GetFolder(strSourcefolderpath) Set Sourcefilelist = aSourceFilearray.Files Set aFileArrayDestination = objFSO.GetFolder(strDestinationfolderpath) Set FileListDestination = aFileArrayDestination.Files For each oFileSource in Sourcefilelist str1= Mid(oFileSource,15,12) str2 = Mid(oFileSource,27,8) str3 = Mid(oFileSource,35,4) If str1 = "lcms_backup_" then osourcename = str1&str2&str3&".bak" End If sFSpec = osourcename Set oFile = objFSO.GetFile(sFSpec) sFileName = oFile.Name For each oFileDestination in FileListDestination bDestinationExists = 0 If sFileName.Name = oFileDestination.Name then If sFileName.DateLastModified = oFileDestination.DateLastModified Then bDestinationExists = 1 Exit For End If End If Next If bDestinationExists = 0 then sFileName.Copy strDestinationfolderpath & "\" & sFileName.Name MsgBox "copy" End If Next End Sub Thanks Raknahs
|
|
| |
|
|
|
 |
RE: File copy error - 1/4/2007 1:32:19 AM
|
|
 |
|
| |
Raknahs
Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
|
Hi, Thanks for your help. I just worked on the code given by you. It works fine. I have a very small problem from the last line when the destination file gets compare with the source file its not getting updated. I have the error "object required sFilename" can u pls. help me out . The error line is highlighted in the Bold. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = wscript.CreateObject("wscript.network") SOURCE_FOLDER = "c:\sourcetest\" DESTINATION_FOLDER = "c:\test_dst\" ReplicateFiles objFSO, SOURCE_FOLDER, DESTINATION_FOLDER Sub ReplicateFiles (objFSO, strSourcefolderpath, strDestinationfolderpath) Dim aSourceFilearray Dim aDestinationfilearray Dim Sourcefilelist Dim Destinationfilelist Dim oFileSource Dim oFileDestination Dim bSourceExists Dim bDestinationExists Dim osourcename Dim sFSpec Dim oFile Dim sFileName 'On Error Resume Next Set aSourceFilearray = objFSO.GetFolder(strSourcefolderpath) Set Sourcefilelist = aSourceFilearray.Files Set aFileArrayDestination = objFSO.GetFolder(strDestinationfolderpath) Set FileListDestination = aFileArrayDestination.Files For each oFileSource in Sourcefilelist str = Mid(oFileSource,1,14) str1= Mid(oFileSource,15,12) str2 = Mid(oFileSource,27,8) str3 = Mid(oFileSource,35,4) If str1 = "lcms_backup_" then osourcename = str&str1&str2&str3&".bak" End If sFSpec = osourcename Set oFile = objfso.GetFile(sFSpec) sFileName = oFile.Name For each oFileDestination in FileListDestination bDestinationExists = 0 If sFileName = oFileDestination.Name then If sFileName.DateLastModified = oFileDestination.DateLastModified Then bDestinationExists = 1 Exit For End If End If Next If bDestinationExists = 0 then MsgBox sFileName sFileName.Copy strDestinationfolderpath & "\" & sFileName.Name MsgBox "copy" End If Next End Sub Thanks Raknahs
|
|
| |
|
|
|
 |
RE: File copy error - 1/4/2007 2:39:57 AM
|
|
 |
|
| |
ebgreen
Posts: 4946
Score: 31
Joined: 7/12/2005
Status: offline
|
The problem is that sFileName is a string but you are treating it as an object. It does not have a .Name property. Instead of sFileName, you should just drop the .Name altogether.
_____________________________
"... 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/4/2007 4:02:00 AM
|
|
 |
|
| |
Raknahs
Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
|
I tried to remove the .name from sFilename.name Still the error exists, any advice. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = wscript.CreateObject("wscript.network") SOURCE_FOLDER = "c:\sourcetest\" DESTINATION_FOLDER = "c:\test_dst\" ReplicateFiles objFSO, SOURCE_FOLDER, DESTINATION_FOLDER Sub ReplicateFiles (objFSO, strSourcefolderpath, strDestinationfolderpath) Dim aSourceFilearray Dim aDestinationfilearray Dim Sourcefilelist Dim Destinationfilelist Dim oFileSource Dim oFileDestination Dim bSourceExists Dim bDestinationExists Dim osourcename Dim sFSpec Dim oFile Dim sFileName 'On Error Resume Next Set aSourceFilearray = objFSO.GetFolder(strSourcefolderpath) Set Sourcefilelist = aSourceFilearray.Files Set aFileArrayDestination = objFSO.GetFolder(strDestinationfolderpath) Set FileListDestination = aFileArrayDestination.Files For each oFileSource in Sourcefilelist str = Mid(oFileSource,1,14) str1= Mid(oFileSource,15,12) str2 = Mid(oFileSource,27,8) str3 = Mid(oFileSource,35,4) If str1 = "lcms_backup_" then osourcename = str&str1&str2&str3&".bak" End If sFSpec = osourcename Set oFile = objfso.GetFile(sFSpec) sFileName = oFile.Name For each oFileDestination in FileListDestination bDestinationExists = 0 If sFileName = oFileDestination.Name then If sFileName.DateLastModified = oFileDestination.DateLastModified Then bDestinationExists = 1 Exit For End If End If Next If bDestinationExists = 0 then sFileName.copy strDestinationfolderpath & "\" & sFileName --- [error (object required: 'sFileName')] MsgBox "file successfully copied" End If Next End Sub Thanks Raknahs
|
|
| |
|
|
|
 |
RE: File copy error - 1/4/2007 4:21:03 AM
|
|
 |
|
| |
ebgreen
Posts: 4946
Score: 31
Joined: 7/12/2005
Status: offline
|
I should have been more explicit. sFileName is not an object. since it is not an object, it does not have any methods or properties. Specifically it does not have a .Copy method. You need to use the actual file object that you want to copy.
_____________________________
"... 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/4/2007 5:48:25 AM
|
|
 |
|
| |
ebgreen
Posts: 4946
Score: 31
Joined: 7/12/2005
Status: offline
|
To best help you we need to understand what you are trying to do. It looks like you want to copy all of the files from a source directory to a target directory. If the file name has a specific string in it then you want to rename it to a different name. If the file already exists in the destination directory and the mod date is the same then you don't want to copy it. Is this an accurate statement of your goals?
_____________________________
"... 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/4/2007 7:41:44 AM
|
|
 |
|
| |
Raknahs
Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
|
This is the coding I tried to delete the destination folder files Pls. advice where do i made a mistake. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = wscript.CreateObject("wscript.network") SOURCE_FOLDER = "c:\sourcetest\" DESTINATION_FOLDER = "c:\test_dst\" ReplicateFiles objFSO, SOURCE_FOLDER, DESTINATION_FOLDER Sub ReplicateFiles (objFSO, strSourcefolderpath, strDestinationfolderpath) Dim aSourceFilearray Dim aDestinationfilearray Dim Sourcefilelist Dim Destinationfilelist Dim oFileSource Dim oFileDestination Dim bSourceExists Dim bDestinationExists Dim osourcename Dim sFSpec Dim oFile Dim ofile1 Dim sFileName Dim sfilename1 Dim sfspecfiles 'On Error Resume Next Set aSourceFilearray = objFSO.GetFolder(strSourcefolderpath) Set Sourcefilelist = aSourceFilearray.Files Set aFileArrayDestination = objFSO.GetFolder(strDestinationfolderpath) Set FileListDestination = aFileArrayDestination.Files For each oFileSource in Sourcefilelist str = Mid(oFileSource,1,14) str1= Mid(oFileSource,15,12) str2 = Mid(oFileSource,27,8) str3 = Mid(oFileSource,35,4) If str1 = "lcms_backup_" then osourcename = str&str1&str2&str3&".bak" End If sFSpec = osourcename Set oFile = objfso.GetFile(sFSpec) sFileName = oFile.Name For each oFileDestination in FileListDestination bDestinationExists = 0 If sFileName = oFileDestination.Name then If sFileName = oFileDestination.DateLastModified Then bDestinationExists = 1 Exit For End If End If Next If bDestinationExists = 0 then oFile.Copy strDestinationfolderpath & "\" & oFile.Name End If Next For each oFileDestination in FileListDestination bSourceExists = 0 sFSpec = osourcename Set oFile = objfso.GetFile(sFSpec) sfilename = oFile.Name If oFiledestination.Name = ofile.Name then If oFiledestination.DateLastModified = oFile.DateLastModified Then bSourceExists = 1 Exit For End If End If If bSourceExists = 0 then oBJFSO.DeleteFile strDestinationfolderpath & "\" & oFileDestination.Name,true End If MsgBox "Files Replicated Successfully" Next End Sub Thanks Raknahs
|
|
| |
|
|
|
|
|