Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


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 >> File copy error
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 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
 
 
Post #: 1
 
 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

(in reply to Raknahs)
 
 
Post #: 2
 
 RE: File copy error - 1/3/2007 6:46:21 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
quote:

ORIGINAL: dm_4ever
i.e. osourcename = objFSO.GetFile(filespec)


Set osourcename = objFSO.GetFile(filespec)

(in reply to dm_4ever)
 
 
Post #: 3
 
 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

(in reply to dm_4ever)
 
 
Post #: 4
 
 RE: File copy error - 1/3/2007 7:42:52 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Raknahs,

I think you want to compare oFileDestination.Name and oFileDestination.DateLastModified
against a given string and a given date. Then use code like

   If sFileName = oFileDestination.Name then
   ...
   If dtLastModified = oFileDestination.DateLastModified Then

Of course you'll have to set these variables before the

   For each oFileDestination in FileListDestination

loop. If you get these values from another (source) file then use code like this:

   Dim sFSpec : sFSpec   = "FullFilespecOfSourcefile"
   Dim oFile     : Set oFile = objFSO.GetFile( sFSpec )
   Dim  sFileName : sFileName = oFile.Name

I further think your code doesn't initialize osourcename, except

     If str1 = "lcms_backup_" then
        osourcename = str1&str2&str3&".bak"

What happens in all other cases?

(in reply to Raknahs)
 
 
Post #: 5
 
 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



(in reply to ehvbs)
 
 
Post #: 6
 
 RE: File copy error - 1/3/2007 9:25:48 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Raknahs,

your code

   sFSpec   = osourcename
   Set oFile = objFSO.GetFile(sFSpec) 

will fail (file not found), if osourcename  (and therefore sFSpec) does not contain a string consisting
of a valid file specification. Insert a

   MsgBox "|" + sFSpec + "|"

between those two lines, to see whether you ask objFSO.GetFile(sFSpec) for the file you want.
Check carefully under which condition osourcename will be set (and how).

Please think about the difference between objects (like files) and string (containing specs/names
of files). If you want to use a string in your comparison, you can't treat a string like an object;

   If  sFileName.Name = oFileDestination.Name then

should either be

  If  sFileName = oFileDestination.Name then

or

  If oFile.Name = oFileDestination.Name then

(in reply to Raknahs)
 
 
Post #: 7
 
 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

(in reply to ehvbs)
 
 
Post #: 8
 
 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

(in reply to Raknahs)
 
 
Post #: 9
 
 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

(in reply to ebgreen)
 
 
Post #: 10
 
 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

(in reply to Raknahs)
 
 
Post #: 11
 
 RE: File copy error - 1/4/2007 5:38:24 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
can u pls. advice how do i copy the specific file from the source folder to the destination folder. This is what actually i am trying to work on this script.


Thanks
Raknahs.

(in reply to ebgreen)
 
 
Post #: 12
 
 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

(in reply to Raknahs)
 
 
Post #: 13
 
 RE: File copy error - 1/4/2007 6:08:58 AM   
  ebgreen


Posts: 4946
Score: 31
Joined: 7/12/2005
Status: offline
If the description that I posted above is accurate then this should work (it is off the cuff and not tested so it might need some fine tuning):


      

_____________________________

"... 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 ebgreen)
 
 
Post #: 14
 
 RE: File copy error - 1/4/2007 6:40:02 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
Let me explain clearly. I have 2 server 1. Production server and the Backup server.

Everday the new files getting created into the production server for ex.  First day the following files getting created lcms_20071001.bak,master_20071001.bak,prd_20071001.bak. second day the following files getting created lcms_20070201.bak,master_20070201.bak,prd_20070201.bak  Keep on creating every day.

I want to copy the production server files into the backup server. Every week i am copying thru manually. I planned to develop a script. I dont want to copy all the files available in the production server, need to copy only a specific files. for ex. lcms_20071001.bak,lcms_20070201.bak.


I need two things from this script.

1. When there is any new files gets created the specific files which is available in the production server has to update in the destination server i.e. backup server.

2. The Destination  server has to verify the files from the source server. If any files find  in the destination server but  not find in the source server, The files which is available in the destination server has to remove immediately.

I have developed a script, the problem in the script is it used to compare all the files its not taking a specific files.

1. The script is updating all the files from the source server to the destination server 
2. Destination server verify all the file  from the source server any files not available in the source folder the destionation folder gets deleted immediately.

This is what i have planned  to develop. Can u help me out for this scenario.


Thanks
Raknahs

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: File copy error - 1/4/2007 6:43:35 AM   
  ebgreen


Posts: 4946
Score: 31
Joined: 7/12/2005
Status: offline
So you only want to archive the "lcms_" files?

_____________________________

"... 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 #: 16
 
 RE: File copy error - 1/4/2007 7:20:46 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
I want to archieve 2 files lcms_file  & master_ file

Also I tried to Implement the code which has been provided by you. Now i am able to copy the  specific file (lcms_) newly created files from the source folder to the destination folder. 1st requirement gets done, 

I need to get the second requirement i.e. The Destination folder file  has to verify from the source folder file If any entries is not find in the source folder, The same entries available in the destination folder , the destination folder file has to remove the file from destination folder..

Can u pls. help me out to complete the second requirement.

Thanks in advance.


Raknahs

(in reply to ebgreen)
 
 
Post #: 17
 
 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

(in reply to Raknahs)
 
 
Post #: 18
 
 RE: File copy error - 1/4/2007 8:17:40 AM   
  ebgreen


Posts: 4946
Score: 31
Joined: 7/12/2005
Status: offline
What is the extension on the files in the source folder? Is it .bak?

_____________________________

"... 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 #: 19
 
 RE: File copy error - 1/4/2007 8:22:46 AM   
  Raknahs

 

Posts: 62
Score: 0
Joined: 12/5/2006
Status: offline
Yes, It is .bak extension.




Thanks
Raknahs

(in reply to ebgreen)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

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