Link to home
Start Free TrialLog in
Avatar of Vincent_Monaghan
Vincent_MonaghanFlag for Ireland

asked on

Cannot copy using Scripting.FileSystemObject on Windows Server 2003

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
Avatar of Louis01
Louis01
Flag of South Africa image

What does
    fso.CopyFile Trim(strFromFile), Trim(strToFile), True
do?
Avatar of sirbounty
What about using this method?

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

ASKER

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



SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JohnBPrice
JohnBPrice

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

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


ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi JohnBPrice

Well spotted. I'll stick a few msgboxes in to see what happens
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.