PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CFindFile class  (Read 573 times)

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
CFindFile class
« on: May 31, 2018, 02:46:25 PM »

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

Code: [Select]
' ========================================================================================
' 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.


Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: CFindFile class
« Reply #1 on: May 31, 2018, 03:49:21 PM »

Sorry that I didn't post the example. That might make it easier for you to see what I am talking about.
Code: [Select]

#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


Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: CFindFile class
« Reply #2 on: May 31, 2018, 04:04:23 PM »

Apparently I missed that GetFullPathName remark. I have changed the code to:

Code: [Select]
' ========================================================================================
' Method FilePath
' FilePath returns the entire path for the file.
' ========================================================================================
PRIVATE FUNCTION CFindFile.FilePath () AS CWSTR
   RETURN this.Root & m_FileInfo.cFileName
END FUNCTION
' ========================================================================================
« Last Edit: May 31, 2018, 04:07:15 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: CFindFile class
« Reply #3 on: May 31, 2018, 04:42:33 PM »

Looks good. The change works as expected. Thanks
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: CFindFile class
« Reply #4 on: October 19, 2018, 03:19:31 PM »

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

Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: CFindFile class
« Reply #5 on: October 19, 2018, 10:25:27 PM »

Thanks for spotting it. I have modified the documentation.