Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. FileSystemObject, Trace and Compiled Difference?

FileSystemObject, Trace and Compiled Difference?

Scheduled Pinned Locked Moved Visual Basic
debuggingquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Riley
    wrote on last edited by
    #1

    Okay, I admit defeat, I've been looking at this for a long time and I can't figure it out. Look at the following code (VB6): Private Sub CmdCopy(ByVal sourceFileOrDir As String, _ ByVal targetDir As String) Dim fso As New FileSystemObject If fso.FileExists(sourceFileOrDir) Then ' Copy source file to target folder fso.CopyFile sourceFileOrDir, fso.BuildPath(targetDir, fso.GetFileName(sourceFileOrDir)), True ElseIf fso.FolderExists(sourceFileOrDir) Then ' Copy source directory contents to target folder CopyContents sourceFileOrDir, targetDir Else MsgBox sourceFileOrDir & vbCrLf & targetDir End If End Sub The sourceFileOrDir argument has already been validated, so the file/folder must exist. When I run this in trace mode, it runs fine, each file or folder contents are copied as requested. But when I run it compiled, the folder contents copy fine but when sourceFileOrDir is a file, the fso.FileExists function returns false and the message box is displayed. To be more specific, if I set a breakpoint on the first "If" then it works fine, but if I set a breakpoint on the MsgBox line then it doesn't. Can anyone explain this bizarity for me? Is there a workaround? Paul

    H 1 Reply Last reply
    0
    • P Paul Riley

      Okay, I admit defeat, I've been looking at this for a long time and I can't figure it out. Look at the following code (VB6): Private Sub CmdCopy(ByVal sourceFileOrDir As String, _ ByVal targetDir As String) Dim fso As New FileSystemObject If fso.FileExists(sourceFileOrDir) Then ' Copy source file to target folder fso.CopyFile sourceFileOrDir, fso.BuildPath(targetDir, fso.GetFileName(sourceFileOrDir)), True ElseIf fso.FolderExists(sourceFileOrDir) Then ' Copy source directory contents to target folder CopyContents sourceFileOrDir, targetDir Else MsgBox sourceFileOrDir & vbCrLf & targetDir End If End Sub The sourceFileOrDir argument has already been validated, so the file/folder must exist. When I run this in trace mode, it runs fine, each file or folder contents are copied as requested. But when I run it compiled, the folder contents copy fine but when sourceFileOrDir is a file, the fso.FileExists function returns false and the message box is displayed. To be more specific, if I set a breakpoint on the first "If" then it works fine, but if I set a breakpoint on the MsgBox line then it doesn't. Can anyone explain this bizarity for me? Is there a workaround? Paul

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      Paul Riley wrote: To be more specific, if I set a breakpoint on the first "If" then it works fine, but if I set a breakpoint on the MsgBox line then it doesn't. You said you find problems after you compile .. How comes you say you put a breakpoint ? can you show us how you call this function ? do you use App.Path ?

      P 1 Reply Last reply
      0
      • H Hesham Amin

        Paul Riley wrote: To be more specific, if I set a breakpoint on the first "If" then it works fine, but if I set a breakpoint on the MsgBox line then it doesn't. You said you find problems after you compile .. How comes you say you put a breakpoint ? can you show us how you call this function ? do you use App.Path ?

        P Offline
        P Offline
        Paul Riley
        wrote on last edited by
        #3

        hspc wrote: You said you find problems after you compile .. How comes you say you put a breakpoint ? Yeah, that comment was an afterthought when I realised that it wasn't necessarily the compile, just whenever you're not tracing when you hit that line specifically. I didn't explain myself very well... sorry. hspc wrote: can you show us how you call this function ? The calling function is an overly complex iteration that parses a number of scripted files to perform automation functions (in short, it builds a whole bunch of stuff to create InstallShield Developer installers). Trust me, you'd wish you'd never asked :) If you can give me a clue what you might need to see then I can cut it down to only the relevant bits. hspc wrote: do you use App.Path ? No, the filenames are pulled from the script files. Paul

        H 1 Reply Last reply
        0
        • P Paul Riley

          hspc wrote: You said you find problems after you compile .. How comes you say you put a breakpoint ? Yeah, that comment was an afterthought when I realised that it wasn't necessarily the compile, just whenever you're not tracing when you hit that line specifically. I didn't explain myself very well... sorry. hspc wrote: can you show us how you call this function ? The calling function is an overly complex iteration that parses a number of scripted files to perform automation functions (in short, it builds a whole bunch of stuff to create InstallShield Developer installers). Trust me, you'd wish you'd never asked :) If you can give me a clue what you might need to see then I can cut it down to only the relevant bits. hspc wrote: do you use App.Path ? No, the filenames are pulled from the script files. Paul

          H Offline
          H Offline
          Hesham Amin
          wrote on last edited by
          #4

          Sorry I can't help.. I just had doubts about the application startup directory.

          P 1 Reply Last reply
          0
          • H Hesham Amin

            Sorry I can't help.. I just had doubts about the application startup directory.

            P Offline
            P Offline
            Paul Riley
            wrote on last edited by
            #5

            hspc wrote: I just had doubts about the application startup directory. I know what you mean, I've run into that problem before too. :) Thanks for trying anyway. Anyone else? Paul

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups