FileSystemObject, Trace and Compiled Difference?
-
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
ThesourceFileOrDir
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 whensourceFileOrDir
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 -
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
ThesourceFileOrDir
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 whensourceFileOrDir
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? PaulPaul 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 ?
-
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 ?
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
-
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
Sorry I can't help.. I just had doubts about the application startup directory.
-
Sorry I can't help.. I just had doubts about the application startup directory.
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