Solved

Cannot copy using Scripting.FileSystemObject on Windows Server 2003

Posted on 2007-03-23
9
281 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
Comment Utility
What does
    fso.CopyFile Trim(strFromFile), Trim(strToFile), True
do?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 200 total points
Comment Utility
...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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 16

Expert Comment

by:JohnBPrice
Comment Utility
>>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
Comment Utility

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
Comment Utility
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
Comment Utility
Hi JohnBPrice

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

Author Comment

by:Vincent_Monaghan
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now