Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PathStripPath

Status
Not open for further replies.

formerTexan

Programmer
Apr 10, 2004
504
US
I am puzzled by the behavior of the Shell function PathStripPath in a VBA setting in that it merely overwrites the beginning of the string.

If I pass a string "C:\FolderABCD\File.txt" the resultant string value is:

"File.txt BCD\File.txt"

This is fortunately not a show stopper since there are alternative ways to trim off the path, but if there are any ideas as to why the behavioral oddity, I'd appreciate hearing them.

Thanks,
Bill
 
It isn't doing anything odd or strange. It is doing exactly what it is documented to do, which is to return a null-terminated string in the buffer you have provided. VB doesn't understand null-terminated strings (in the sense that it doesn't know that CHR(0) is a string terminator), so when you display the string it actually displays the entire original buffer, which is your original string overwritten at the beginning by the stripped filename plus a CHR(0)

So you need to extract

Left$(strResult, instr(strResult, Chr$(0))-1)

or

Split(strResult,Chr$(0))(0)
 
Thanks much Strongm. Yes indeed that return is null terminated. The API documentation was a bit ambiguous about the results and they weren't what I expected.

Since I am only looping through a few dozen paths at the most, speed isn't an issue. But I will have to see whether it is more efficient to just use VB string functions or the API call or alternatively pass a fixed length string. The fixed length string gets a cleaner result, but the tail of the string still must be clipped.

Again, I appreciate your feedback.
Cheers, Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top