Hi Jose,
I am using your CFindFile class to recursively iterate over all files and subfolders in the compiler's \inc folder structure. Everything is working okay except for when I try to us CFindFile.FilePath(). From my reading it appears that the .GetFullPathName merges the *current folder* with the filename. In my case, I never change the working folder so the folder that gets appended to the found filename is always the folder of the running EXE.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364963(v=vs.85).aspx
' ========================================================================================
' Method FilePath
' FilePath returns the entire path for the file.
' ========================================================================================
PRIVATE FUNCTION CFindFile.FilePath () AS CWSTR
DIM nLen AS LONG, buffer AS WSTRING * 4096
nLen = .GetFullPathNameW(m_FileInfo.cFileName, SIZEOF(buffer) \ 2, buffer, NULL)
IF nLen THEN RETURN LEFT(buffer, nLen)
RETURN ""
END FUNCTION
Maybe CFindFile.FilePath should be a combination of CFindFile.Root and m_FileInfo.cFileName ?
I hope I explained that okay.
Sorry that I didn't post the example. That might make it easier for you to see what I am talking about.
#Define unicode
#INCLUDE ONCE "windows.bi"
#INCLUDE ONCE "Afx/CFindFile.inc"
USING Afx
function PreparseFolder( byval cwsPath as CWSTR ) as Long
? "Processing: "; cwsPath
DIM pFinder AS CFindFile
IF pFinder.FindFile(cwsPath) = S_OK THEN
print ".."; cwsPath
DO
IF pFinder.IsDots = FALSE THEN ' // skip . and .. files
' If the file is a subfolder then recurse into that folder and process
if pFinder.IsFolder then
' print "*IsFolder: "; pFinder.FilePath 'pFinder.Filename
' PreparseFolder(pFinder.FilePath & "\*.*")
PreparseFolder(pFinder.Root & pFinder.FileNameX & "\*.*")
else
PRINT " "; pFinder.FileNameX
end if
END IF
IF pFinder.FindNext = 0 THEN EXIT DO
LOOP
END IF
pFinder.Close
function = 0
END FUNCTION
PreparseFolder("x:\FB\FreeBASIC-1.06.0-win32\inc\*.*")
sleep
Apparently I missed that GetFullPathName remark. I have changed the code to:
' ========================================================================================
' Method FilePath
' FilePath returns the entire path for the file.
' ========================================================================================
PRIVATE FUNCTION CFindFile.FilePath () AS CWSTR
RETURN this.Root & m_FileInfo.cFileName
END FUNCTION
' ========================================================================================
Looks good. The change works as expected. Thanks
Hi José,
Small mixup in the documentation for CFindFile class. The descriptions for the methods "FileName" and "FileNameX" are backwards. I have added my comments in bold.
FileName
Call this method to get the title name of the found file excluding the file extension.
FUNCTION FileName () AS CWSTR
Return value
The name of the most-recently-found file, including excluding the file extension. For example, calling FileName to generate a user message about the file c:\myhtml\myfile.txt returns the file name myfile.txt myfile.
FileNameX
Call this method to get the name of the found file including the file extension.
FUNCTION FileNameX () AS CWSTR
Return value
The name of the most-recently-found file, excluding including the extension. For example, calling FileNameX to generate a user message about the file c:\myhtml\myfile.txt returns the file name myfile myfile.txt.
Not sure about the phrase "to generate a user message".
Also, under the FileExt descriotion:
The extension of the most-recently-found filen filename
Thanks for spotting it. I have modified the documentation.