|
Post by rodsweb on Apr 5, 2022 16:17:27 GMT -5
I am sure someone has done this before, so to save me re-inventing the wheel can anyone give me code to go thru files as we do with File explorer and find a file (lots of files to be chosen)? On selecting the desired file I need to input the path and the file name into an LB variable.
|
|
|
Post by Chris Iverson on Apr 5, 2022 17:17:37 GMT -5
I think you're looking for the FILEDIALOG command. Looking that command up in the helpfile will give you usage demos, as well.
|
|
|
Post by rodsweb on Apr 6, 2022 8:34:38 GMT -5
Too easy. Thanks I didn't notice that command.
|
|
coda
Junior Member
Posts: 74
|
Post by coda on Apr 6, 2022 15:03:56 GMT -5
Before you ask your next question, if you need to segment the filename and path when retrieved or perform various other operations, you can use these functions:
'FUNCTIONS FOR DETECTING FILEPATH EXISTENCE, VALIDATION & SEGMENTATION
'return a true if the file in fullPath$ exists, else return false function fileExists(fullPath$) files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$() fileExists = val(info$(0, 0)) > 0 end function
'return just the directory path from a full file path function pathOnly$(fullPath$) pathOnly$ = fullPath$ while right$(pathOnly$, 1) <> "\" and pathOnly$ <> "" pathOnly$ = left$(pathOnly$, len(pathOnly$)-1) wend end function
'return just the filename from a full file path function filenameOnly$(fullPath$) pathLength = len(pathOnly$(fullPath$)) filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength) end function
'return a true if the path in fullPath$ exists, else return false function pathExists(fullPath$) files pathOnly$(fullPath$), "NUL", info$() pathExists = val(info$(0, 0)) > 0 if (pathOnly$(fullPath$) = "") OR (pathOnly$(fullPath$) = "\") then 'I had to add this condition because it's strange but if the path being tested is "" the function returns a true (1) otherwise. I can't figure out why but it doesn't matter. This fixes the problem. pathExists = 0 end if end function
'return just the file name without extension from a full file path function GetFilenameMinusExtension$(fullPath$) i = 1 while mid$(filenameOnly$(fullPath$), i, 1) <> "." and mid$(filenameOnly$(fullPath$), i, 1) <> "" i = i+1 wend GetFilenameMinusExtension$ = mid$(filenameOnly$(fullPath$), 1, i-1) end function
'return just the extension from a full file path function ExtensionOnly$(fullPath$) i=1 while mid$(filenameOnly$(fullPath$), i, 1) <> "." and mid$(filenameOnly$(fullPath$), i, 1) <> "" i = i+1 wend if mid$(filenameOnly$(fullPath$), i, 1) = "." then i = i+1 while mid$(filenameOnly$(fullPath$), i, 1) <> "" ExtensionOnly$ = ExtensionOnly$ + mid$(filenameOnly$(fullPath$), i, 1) i = i+1 wend else ExtensionOnly$ = "" end if end function
'returm a true if the filename in a full save path (fullPath$) exists and does not contain characters prohibited by Windows TM, else return a false function ValidSaveName(fullPath$) ValidSaveName = 1 i = 1 while mid$(filenameOnly$(fullPath$), i, 1) <> "" na$=mid$(filenameOnly$(fullPath$), i, 1) ' detect \/:*?"<>| (Charcters disallowed by Windows TM in filenames) if (na$ = CHR$(92)) OR (na$ = CHR$(47)) OR (na$ = CHR$(58)) OR (na$ = CHR$(42)) OR (na$ = CHR$(63)) OR (na$ = CHR$(34)) OR (na$ = CHR$(60)) OR (na$ = CHR$(62)) OR (na$ = CHR$(124)) then ValidSaveName = 0 end if i = i+1 wend if GetFilenameMinusExtension$(fullPath$) = "" then ValidSaveName = 0 end if end function
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Apr 7, 2022 7:50:50 GMT -5
Oh that might be handy, thank you coda
|
|