473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Almost embarrarased to ask this string manipulation question....

I am looking for an elegant way to return just the directory part of a string that
represents a fully qualified path to a file.

Example:
MyString = c:\MyDir\Mydir2\Mydir3\Myfile1.txt
I want to return just c:\MyDir\Mydir2\Mydir3

Thanks!

Nov 21 '05 #1
4 833
Not to mention my spelling of 'embarrassed'!
Nov 21 '05 #2
I always ask questions around here, but now I can actually help out! :)

Imports system.io

dim path as string = "c:\MyDir\Mydir2\Mydir3\Myfile1*.txt"
dim result as string
result = path.getdirectoryname(path)

Haven't tested it, but i think this should work. No text parsing
necessary! :)

John

Nov 21 '05 #3
system.io.path.getdirectoryname(path) worked like a charm.
Cheers!
"johnb41" <or****@informatik.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I always ask questions around here, but now I can actually help out! :)

Imports system.io

dim path as string = "c:\MyDir\Mydir2\Mydir3\Myfile1*.txt"
dim result as string
result = path.getdirectoryname(path)

Haven't tested it, but i think this should work. No text parsing
necessary! :)

John
Nov 21 '05 #4
Hey! I'm glad you posted that! I have been using a really convoluted bit of code to get the same results to add file name only
to a listbox. Went from several lines of code to TWO!!
Thanks for sharing.
james
"Darious Snell" <nu**@sdlkfweu.org> wrote in message news:11*************@corp.supernews.com...
system.io.path.getdirectoryname(path) worked like a charm.
Cheers!
"johnb41" <or****@informatik.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I always ask questions around here, but now I can actually help out! :)

Imports system.io

dim path as string = "c:\MyDir\Mydir2\Mydir3\Myfile1*.txt"
dim result as string
result = path.getdirectoryname(path)

Haven't tested it, but i think this should work. No text parsing
necessary! :)

John

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CoolPint | last post by:
Is there any way I can reduce the size of internal buffer to store characters by std::string? After having used a string object to store large strings, the object seems to retain the large...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
16
by: zohaibbaloch | last post by:
how to manipulate string without using arrays.manipulation example i have to print dog or any string i want to cut d from dog and paste it a end and add a at the last dog becoms ogda. please...
4
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
7
by: John A Grandy | last post by:
what are the preferred VB.NET analogues for IsNumeric() and Len() and CInt() & similar string-manipulation functions in VB6
22
by: Nunaya | last post by:
We have developed two objects called "customer" and "salesrep". For simplicity, assume that these two objects will talk directly to a database. The database has three tables: customers,...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
7
by: Ryan | last post by:
I'm in the process of learning more about building my ASP.NET website to use my SQL datastore and am a bit confused about how ADO.NET works with ASP.NET. This Microsoft article implies that using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.