PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CFindFile class  (Read 366 times)

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8553
  • 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: 8553
  • 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: 3087
    • 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: 8553
  • 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