×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

PathStripPath

PathStripPath

PathStripPath

(OP)
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

RE: PathStripPath

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)

RE: PathStripPath

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close