Active Forums > QB64 Discussion
_FileExists not working with wildcards
hanness:
Thanks for the suggestions. My example was simplified. The actual files in questions and not straight incrementing serial numbers. They actually contain a version number. Here is an example:
WIM_TOOLS_5.1.1.100.txt
I just tried my little fake file idea, and it works perfectly.
Funny, I was stumped by this for 2 hours. 2 minutes after I posted my question that idea spring into my head.
bplus:
I would use a shell command to delete files with wildcards.
luke:
It's fundamentally the wrong idea to rely on _fileexists to say whether or not an IO operation will succeed. The file might exist but you have insufficient permission to open/delete it, another program might remove the file between your program checking and using the file, there may be a network error (if the file is from a network share). A more robust solution is to simply catch the error and respond accordingly:
--- Code: ---'At the top of the program
On Error Goto general_error
Dim Shared Error_happened As Long
'Main Program
End
general_error:
Print "Fatal error"; err; "at line"; _errorline
end
io_error:
Error_happened = err
Resume Next
Sub delete_files(names$)
Error_happened = 0
On Error Goto io_error
Kill names$
On Error Goto general_error
If Error_happened then
'Ignore or inform user, depending on use case
End If
End Sub
--- End code ---
hanness:
Luke, I understand what you are saying, but in my particular use scenario, those concerns will never apply. I will ALWAYS have sufficient permission to delete those files, and it is 100% guaranteed that nothing else will remove the file.
But I do still understand and appreciate your point.
bplus:
--- Quote from: bplus on April 14, 2022, 07:05:05 pm ---I would use a shell command to delete files with wildcards.
--- End quote ---
Really it's just one line of code? Why not that? Too easy!
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version