|
Post by Walt Decker on Jun 21, 2023 11:22:39 GMT -5
What is "Z:\SOMEPATH\SOMEFILE\MYFILES"; directory or file? What is "Z:\SOMEPATH\SOMEFILE\MYFILES.FIL"; directory or file? That depends on how it is created. Windows(tm) does not care. Z = MKDIR("Z:\SOMEPATH\SOMEFILE\MYFILES") creates a directory if it has not been created and if it is not a file. Z = MKDIR("Z:\SOMEPATH\SOMEFILE\MYFILES.FIL") creates a directory if it has not been created and if it is not a file. OPEN "Z:\SOMEPATH\SOMEFILE\MYFILES" FOR RANDOM AS #FO creates a file if it is not a directory. OPEN "Z:\SOMEPATH\SOMEFILE\MYFILES.FIL" FOR RANDOM AS #FO creates a file if it is not a directory. Liberty Basic does not provide a good way to determine if a given path is a directory or a file. If one wants to determine if the file "Z:\SOMEPATH\SOMEFILE\MYFILES" exists, LB's FILES() function will not find it; it is treated as a directoy instead of a file. What you can do is search "Z:\SOMEPATH\SOMEFILE" with the wild-card "*.*" then parse through the array looking for "MYFILES". On the other hand, if one is not adverse to using CALLDLL one can query FN_Dir.dll functions FN_DirExists() and FN_FileExists(). FN_Dir.dll can be found HERE
|
|
|
Post by Brandon Parker on Jul 4, 2023 14:55:23 GMT -5
Is there something terribly difficult or wrong with this approach? This uses the built-in LB "FILES" command which is very powerful when you understand how it works and what it returns.
Global False : False = 0 Global True : True = 1
Dim Info$(0, 0)
' "Basic Languages exists as both a folder and a text file in my D:\ directory. ' The functions below return the following which is completed expected" ' - 0 ' - 1 ' - 1 ' - 0 ' - 1
'This does not find the file Print fileExists("D:\", "Basic Languages") 'This finds the file Print fileExists("D:\", "Basic Languages.txt") 'This finds the file Print fileExists("D:\", "Basic Languages*")
'This does not find the folder Print searchForFolder("D:\", "Basic Languages.txt") 'This finds the folder Print searchForFolder("D:\", "Basic Languages") End
'_________________________________________________________________________________________________________________________________________________________ '_________________________________________________________________________________________________________________________________________________________
Function fileExists(path$, filename$) Files path$, filename$, Info$() fileExists = Val(Info$(0, 0)) ReDim Info$(0, 0) End Function
'_________________________________________________________________________________________________________________________________________________________ '_________________________________________________________________________________________________________________________________________________________
Function searchForFolder(directory$, folder$) On Error GoTo [Error] directory$ = directory$ + "\" Files directory$, "*", Info$() If Val(Info$(0,1)) > 0 Then For i = 1 To Val(Info$(0,1)) If Lower$(Info$(Val(Info$(0,0)) + i, 1)) = Lower$(folder$) Then searchForFolder = True Exit For End If Next i End If ReDim Info$(0, 0) [Error] End Function
{:0)
Brandon Parker
|
|
|
Post by Walt Decker on Jul 7, 2023 16:38:18 GMT -5
No, other than it is cludgy. There are better ways.
|
|
|
Post by Brandon Parker on Jul 8, 2023 14:38:22 GMT -5
Personally, I would disagree. Using two functions built with native LB code doing the exact thing the "Files" command was designed to do seems much better than handing it off to a DLL which is only using the exact same underlying system that LB is using in the end. That is my opinion though...
{:0)
Brandon Parker
|
|
|
Post by Walt Decker on Jul 8, 2023 17:06:11 GMT -5
I was referring to FindFirstFile() and FindNextFile().
|
|