473,508 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Don't show full path

The Directory.GetFiles method will bring back the file name including the
path. I just want the file name, not the path.

For Each strFile In Directory.GetFiles(strLocalPath)
Me.lstLocal.Items.Add(strFile.ToString)
Next

Oct 26 '06 #1
7 2869

Mike OKC wrote:
The Directory.GetFiles method will bring back the file name including the
path. I just want the file name, not the path.

For Each strFile In Directory.GetFiles(strLocalPath)
Me.lstLocal.Items.Add(strFile.ToString)
Next
FileInfo class.

Oct 26 '06 #2
Use My.Computer.FileSystem.GetName() to parse the filename out of a full
path.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
The Directory.GetFiles method will bring back the file name including
the path. I just want the file name, not the path.

For Each strFile In Directory.GetFiles(strLocalPath)
Me.lstLocal.Items.Add(strFile.ToString)
Next

Oct 26 '06 #3


"Mike OKC" <Mi*****@newsgroups.nospamwrote in message
news:33**********************************@microsof t.com...
The Directory.GetFiles method will bring back the file name including the
path. I just want the file name, not the path.

For Each strFile In Directory.GetFiles(strLocalPath)
Me.lstLocal.Items.Add(strFile.ToString)
Next
In v1.1, I use Path.GetFileName(path) to get a filename without the
directory path :)

Review the other posts for newer versions.

HTH,
Mythran
Oct 26 '06 #4
"Mythran" <ki********@hotmail.comschrieb:
>The Directory.GetFiles method will bring back the file name including the
path. I just want the file name, not the path.

For Each strFile In Directory.GetFiles(strLocalPath)
Me.lstLocal.Items.Add(strFile.ToString)
Next

In v1.1, I use Path.GetFileName(path) to get a filename without the
directory path :)
I even use it in .NET 2.0 if I have a file path as a string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Oct 26 '06 #5

Herfried K. Wagner [MVP] wrote:
"Mythran" <ki********@hotmail.comschrieb:
The Directory.GetFiles method will bring back the file name including the
path. I just want the file name, not the path.

For Each strFile In Directory.GetFiles(strLocalPath)
Me.lstLocal.Items.Add(strFile.ToString)
Next
In v1.1, I use Path.GetFileName(path) to get a filename without the
directory path :)

I even use it in .NET 2.0 if I have a file path as a string.

Me too. Much easier then My.... Oh, yeah - it also doesn't hurt that
I do all my coding in C# actaully :)

--
Tom Shelton

Oct 27 '06 #6
Hi Mike,

Yes, you're right. The Directory.GetFiles method returns the names of files
with full path in a specified directory.

If you would like to get only the file names in a specified directory, you
could call DirectoryInfo.GetFiles method which returns an array of type
FileInfo and then use the FileInfo.Name property to get the file name
without full path.

The following is a sample.

Dim di As DirectoryInfo = New DirectoryInfo(strLocalPath)
Dim fi As FileInfo() = di.GetFiles()

For Each fiTemp As FileInfo In fi
Console.WriteLine(fiTemp.Name)
Next

Hope this help.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 27 '06 #7
It worked. Thanks.

Also, thanks for the detailed focused response, it really helped me that you
provided a detailed explaination and an example.

"Linda Liu [MSFT]" wrote:
Hi Mike,

Yes, you're right. The Directory.GetFiles method returns the names of files
with full path in a specified directory.

If you would like to get only the file names in a specified directory, you
could call DirectoryInfo.GetFiles method which returns an array of type
FileInfo and then use the FileInfo.Name property to get the file name
without full path.

The following is a sample.

Dim di As DirectoryInfo = New DirectoryInfo(strLocalPath)
Dim fi As FileInfo() = di.GetFiles()

For Each fiTemp As FileInfo In fi
Console.WriteLine(fiTemp.Name)
Next

Hope this help.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 27 '06 #8

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

Similar topics

6
3447
by: Arnold | last post by:
Hi there, I've looked at numerous posts out there but have yet to find a solution to this. I have an image control on a main form that shows a linked jpeg thumbnail. Image controls are also on...
2
5238
by: Sridhar | last post by:
Hi, I have a web form where it has a <input type=file id=file1> control. I have an Upload button to upload the file. WHen I click on browse and select one file, it is showing the full file path...
4
4047
by: Dots | last post by:
I have a class library with a method called getpath(). I want to be able to get the full path of a folder and write some files to the (my_files_dir) folder. A console application will use this...
11
8247
by: rh00667 | last post by:
hi all, i'm confused now. how i can get the full path of an application? if myapp is in a directory which belongs to PATH, argv gives me the first token of cmd line, and not the real path of...
17
2500
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this...
5
2595
by: =?Utf-8?B?TWFydHluIEZld3RyZWxs?= | last post by:
Hi there. I posted an earlier issue under the name "That assembly does not allow partially trusted callers" but have now identified what the issue is. As explained before I am working in...
4
3014
by: somank.sharma | last post by:
I am running an exe created in C. I need the full path (absolute path) of this exe. In the first argument of main, I am getting the exe name. How can I get the full path for this exe.
1
1454
by: mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post by:
I think I don't understand how the module search path works... Let's say I have a folders called 'test'. Underneath it, I create two more folders called 'foo' and 'bar'. In 'foo', I create an...
2
3322
by: tvjraman | last post by:
I've spent two days on google trying to find a suitable solution for getting the full path of the running process but in vain. My question is very simple. I want to know the full path of the...
0
7129
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
7398
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...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.