Solved

Cannot copy using Scripting.FileSystemObject on Windows Server 2003

Posted on 2007-03-23
9
284 Views
Last Modified: 2013-12-26
I have an app which works as it should in Windows XP pro but when i run it on a sever running Windows Server 2003, it does not work, nor does it give an error. The piece of code that does not work is as follows:

    Dim fso As Object

    Dim strFromFile As String
    Dim strToFile As String
    ...

'   strProcessPath is passed to function after it is tested as valid

'   Copy file to Dir
    strFromFile = Trim(App.Path) & "\SystemConfig.zip"
    strToFile = Trim(strProcessPath) & "\SystemConfig.zip"

    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile Trim(strFromFile), Trim(strToFile)
    Set fso = Nothing
'///////////////////////////////////////////////////////////////

Thanks for your help
0
Comment
Question by:Vincent_Monaghan
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:Louis01
ID: 18778059
What does
    fso.CopyFile Trim(strFromFile), Trim(strToFile), True
do?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18778716
What about using this method?

    Set fso = CreateObject("Scripting.FileSystemObject")
    set objFile=fso.GetFile(strFromFile)
    fso.Copy Trim(strToFile)
0
 

Author Comment

by:Vincent_Monaghan
ID: 18783744
Hi Louise01
    fso.CopyFile Trim(strFromFile), Trim(strToFile), True
This method is used to copy a file from source to destination, just like the DOS copy command.

A useful MS site is : http://support.microsoft.com/kb/q186118/

I have used it many times and it works well but for some reason it did not work running on the MS Windows Server 2003. I have since tried a different method, ie shell out to the CMD environment and run the DOS command copy
Check out on the MS KBase: HOWTO: 32-Bit App Can Determine When a Shelled Process Ends
                                              Q129796
Remember to use the the short names generated for files on NTFS and FAT volumes. for eg
c:\Program Files        -> C:\PROGRA~1

Hi sirbounty
I will give this a try, but it will be several days before I get to it. Thanks



0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 200 total points
ID: 18784168
...even your shelled copy will work with long names, as long as you place quotes on the outside of the paths...chr(34) is the character code...
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 18792554
>>nor does it give an error
Do you have an "On Error resume next" or "on error goto xxxx" anywhere in the procedure or calling procedures that might be supressing an error?

Can you copy the file manually without errors?

Have you checked that strProcessPath is indeed set to what you believe it is?  Maybe it IS copying, but to an unexpected location.
0
 

Author Comment

by:Vincent_Monaghan
ID: 18799129

Hi  JohnBPrice

There is error trapping code in the procedure :

Dim fso As Object

    Dim strFromFile As String
    Dim strToFile As String
    ...


' Error trapping code
    Dim Err_Desc As String
    Dim Err_Source As String
    Dim Err_Msg As String

    On Local Error GoTo ErrorProcessRows



'   strProcessPath is passed to function after it is tested as valid

'   Copy file to Dir
    strFromFile = Trim(App.Path) & "\SystemConfig.zip"
    strToFile = Trim(strProcessPath) & "\SystemConfig.zip"

    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile Trim(strFromFile), Trim(strToFile)
    Set fso = Nothing


    ...

    Exit Sub

ErrorProcessRows:
    Err_Number = Err.Number
    Err_Desc = Err.Description
    Err_Source = Err.Source

    WriteAppLog ("Error Processing Rows; Err : " & str(Err_Number) & ";" & Err_Desc & "; Source :" & Err_Source)
End Sub


Public Function WriteAppLog(ByVal strLogText As String)
    Dim objFileSystem As Object
    Dim objFile As Object
    Dim strFilePath As String
    Dim msg As String
   
    On Error GoTo LogErr
   
    msg = Format(Date, "yyyy-mm-dd") & " " & Format(Time(), "hh:mm:ss") & ";" & Trim(strLogText) & vbCrLf
   
    strFilePath = gstrLogsPath
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFileSystem.OpenTextfile(strFilePath, 8, -1)
    objFile.Write msg
    objFile.Close
    Set objFile = Nothing
    Set objFileSystem = Nothing
    Exit Function
   
LogErr:
End Function

'///////////////////////////////////////////////////////////////
Sorry for repeating the same code as above again. I also include the writelog routine I use. Interestingly it uses the "Scripting.FileSystemObject", but it always works no problem

As to your other points. Yes I can copy manually. The same path works when I shell out and use the DOS copy command in  BATCH file :

copy /y %1 %2

Thanks for your comments


0
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 300 total points
ID: 18800454
With that code, if there is an error with the FileSystemObject, you will get the behavior you see.  The first error flips to ErrorProcessRows, which again tries to use FileSystemObject, and if it still has an error it flips to LogErr: which does nothing, e.g. an error with the FileSystemObject just terminates with no error reporting.

I presume there is nothing in your application log.

I'd try commenting out ALL the "On error" and run it again to see if that is the issue.
0
 

Author Comment

by:Vincent_Monaghan
ID: 18802008
Hi JohnBPrice

Well spotted. I'll stick a few msgboxes in to see what happens
0
 

Author Comment

by:Vincent_Monaghan
ID: 18868983
Thanks all fo your contributions. I have not had time to test the suggestions and give feedback, but wanted to award points before the question was deleted.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question