@José Roca

Windows specific questions.
Post Reply
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

@José Roca

Post by deltarho[1859] »

Hi José

I am not complaining but I am in the process of tidying up a project including replacing CFileSys entries with their Afx counterparts. I got down to only one left namely pFileSys.GetFolderName but I could not find AfxGetFolderName. No big deal but you probably meant to include that one.

There is a lot of really useful Afx* which is making my life very much easier, allowing me more time to code ideas.

Thankyou
PaulSquires
Posts: 999
Joined: Jul 14, 2005 23:41

Re: @José Roca

Post by PaulSquires »

Hi David,

Maybe you should try using the AfxStrPathName function found int AfxStr.inc. It is a lot like the function found in PowerBasic.

' ========================================================================================
' Parses a path/file name to extract component parts.
' This function evaluates a text path/file text name, and returns a requested part of the
' name. The functionality is strictly one of string parsing alone.
' wszOption is one of the following words which is used to specify the requested part:
' PATH
' Returns the path portion of the path/file Name. That is the text up to and
' including the last backslash (\) or colon (:).
' NAME
' Returns the name portion of the path/file Name. That is the text to the right
' of the last backslash (\) or colon (:), ending just before the last period (.).
' EXTN
' Returns the extension portion of the path/file name. That is the last
' period (.) in the string plus the text to the right of it.
' NAMEX
' Returns the name and the EXTN parts combined.
' ========================================================================================
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: @José Roca

Post by Josep Roca »

There is a similar function, AfxGetPathName, but it has a slightly different behaviour, such that it returns the trailing backslash or ":", as it does PowerBasic.

Anyway, I have added to AfxWin.inc the following function, that mimics the GetFolderName method:

Code: Select all

' ========================================================================================
' Returns a string containing the name of the folder for a specified path, i.e. the path
' minus the file name.
' ========================================================================================
PRIVATE FUNCTION AfxGetFolderName (BYREF wszPath AS WSTRING) AS CWSTR
   DIM cwsPath AS CWSTR = wszPath
   DIM p AS LONG
   IF INSTRREV(cwsPath, ".") = 0 THEN
      IF RIGHT(**cwsPath, 1) = "\" THEN cwsPath = LEFT(**cwsPath, LEN(cwsPath) - 1)
      RETURN cwsPath
   END IF
   p = INSTRREV(cwsPath, ANY "\/")
   IF p THEN RETURN LEFT(**cwsPath, p - 1)
   RETURN cwsPath
END FUNCTION
' ========================================================================================
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: @José Roca

Post by Josep Roca »

> No big deal but you probably meant to include that one.

Suggestions for new functions are welcome. I have written so many that sometimes I can't rememember if there is already one available to do a specified task, but there is always room for new ones.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: @José Roca

Post by deltarho[1859] »

Thanks Paul

AfxStrPathName would do it - leaving just the backslash to remove.

There are so many Afx* to soak up.

Grim Reaper: Sorry, buddy - it's your turn.
Me: Gimme a break, I haven't gotten through all the Afx* yet.
Grim Reaper: OK, I will see you later.
Me: Not if I see you first you won't!

AfxGetPathName? Yes.

AfxGetFolderName is even better.

Thanks José

Added: The project in question is now a "Afx/CFileSys.inc" free zone. No doubt that I will add something to upset the apple cart. <smile>
Post Reply