Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_File$ is not behaving as expected, cannot determine why
#1
I'm having some difficulties with _Files$ not behaving as expected. A detailed description of the issue can be found in the comments of the code sample below.

To summarize briefly, _Files$ works fine by itself, but when I introduce a number of lines of code that I currently have commented out, those lines for some unknown reason cause _Files$ to no longer work. Again, see the full description in the comments.

My test scenario:

QB64PE 3.14.1
Windows 11 24H2, latest public release (build 26100.2033)
Logged on as an Administrator

If anyone can provide a clue why this is failing, I would really appreciate some insight. I've been at this for a few hours and cannot put my finger on the problem.


Code: (Select All)
$Debug
$Console:Only
Option _Explicit

Dim MountedImageDriveLetter As String
Dim Cmd As String
Dim GetLine As String
Dim count As Integer
Dim FullPathToImage As String
Dim ISO_Path As String
Dim CurrentFile As String
Dim ff1 As Long
Dim FileSpec As String

' This program is placed in a folder that contains a number of files including files that take the form
' "EXPORTED DRIVERS*.iso". The program is supposed to mount each ISO image file (the first powershell command),
' and then it runs another command sending the output of that command to a file called MountInfo.txt. Next,
' we open MountInfo.txt and read 4 lines. The 4th line will contain the drive letter to which the ISO image was
' mounted. We save the drive letter and a colon (D: as an example) in MountedImageDriveLetter$. We then close
' MountInfo.txt and delete it. As a confirmation we print the drive letter to the screen.
'
' Here now is where the problem begins: We use _File$ to retrieve the next file matching the pattern
' "EXPORTED DRIVERS*.iso". However, upon running this command it returns an empty string rather than the next
' file name. Why???? For the life of me I cannot figure it out!

' Please note that I have commented out all of the lines that do the heavy lifting. In the current state, this
' program simply gets the first file name, prints it to the screen, then it gets the next file name. This works
' flawlessly! But when I uncomment all the lines in the DO loop the line "CurrentFile$ = _Files$" simply returns
' an empty string.

' TIP: I suggest running this in debug mode and then start the program paused. Press F4 and add all variables
' to watch. Then press F7 to step through one line at a time. You will see that the first file name is retrieved
' correctly, but when you reach line 68 it fails to get the next file name when the lines in the DO loop are
' uncommented but it does work with those lines commented out.

' Make sure to create a number of files with a .iso extension in the same folder with the program. These should
' be real ISO image files because we are actually mounting them with this program.

ISO_Path$ = _CWD$

FileSpec$ = ISO_Path$ + "\EXPORTED DRIVERS*.iso"

CurrentFile$ = _Files$(FileSpec$)

Do While Len(CurrentFile$) > 0
    '    MountedImageDriveLetter$ = ""
    '    FullPathToImage$ = ISO_Path$ + "\" + CurrentFile$

    '    Cmd$ = "powershell.exe -command " + Chr$(34) + "Mount-DiskImage " + Chr$(34) + "'" + FullPathToImage$ + "'" + Chr$(34) + Chr$(34) + " > NUL"
    '    Shell Cmd$
    '    Cmd$ = "powershell.exe -command " + Chr$(34) + "Get-DiskImage -ImagePath '" + FullPathToImage$ + "' | Get-Volume" + Chr$(34) + " > MountInfo.txt"
    '    Shell Cmd$

    '    ff1 = FreeFile
    '    Open "MountInfo.txt" For Input As #ff1

    '    For count = 1 To 4
    '        Line Input #ff1, GetLine$
    '    Next count

    '    MountedImageDriveLetter$ = Left$(GetLine$, 1) + ":"
    '    Close #ff1
    '    Kill "MountInfo.txt"

    '    Print MountedImageDriveLetter$
    Print CurrentFile$

    CurrentFile$ = _Files$
Loop


End
Reply


Messages In This Thread
_File$ is not behaving as expected, cannot determine why - by hanness - 10-10-2024, 02:47 AM



Users browsing this thread: 1 Guest(s)