473,320 Members | 1,914 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,320 software developers and data experts.

how to get only the name of the file, not the whole path?

Ben
Hi,

i need the filename of files located in a directory.

I use this:
Directory.GetFiles(Server.MapPath("~/mydirectory/")
For Each fileName In fileEntries
name=fileName
next

but this guves the full path. Any way to get only the filename? Of course i
can use substring, but does it exist a function?
Thanks
Ben

Nov 10 '08 #1
3 1610

"Ben" <be@fd.dcwrote in message
news:OG**************@TK2MSFTNGP05.phx.gbl...
Hi,

i need the filename of files located in a directory.

I use this:
Directory.GetFiles(Server.MapPath("~/mydirectory/")
For Each fileName In fileEntries
name=fileName
next

but this guves the full path. Any way to get only the filename? Of course
i can use substring, but does it exist a function?
Thanks
Ben
Check out the functions in the System.IO.Path namespace. This namespace has
all functions to manipulate file names etc.

LS

Nov 10 '08 #2
FileInfo.Name

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Lloyd Sheen" <a@b.cwrote in message
news:eZ****************@TK2MSFTNGP06.phx.gbl...
>
"Ben" <be@fd.dcwrote in message
news:OG**************@TK2MSFTNGP05.phx.gbl...
>Hi,

i need the filename of files located in a directory.

I use this:
Directory.GetFiles(Server.MapPath("~/mydirectory/")
For Each fileName In fileEntries
name=fileName
next

but this guves the full path. Any way to get only the filename? Of course
i can use substring, but does it exist a function?
Thanks
Ben

Check out the functions in the System.IO.Path namespace. This namespace
has all functions to manipulate file names etc.

LS
Nov 10 '08 #3
On Nov 10, 5:26*pm, "Ben" <b...@fd.dcwrote:
Hi,

i need the filename of files located in a directory.

I use this:
Directory.GetFiles(Server.MapPath("~/mydirectory/")
For Each fileName In fileEntries
name=fileName
next

but this guves the full path. Any way to get only the filename? Of coursei
can use substring, but does it exist a function?
Thanks
Ben
' Create a reference to the current directory.
Dim di As New DirectoryInfo(Environment.CurrentDirectory)
' Create an array representing the files in the current
directory.
Dim fi As FileInfo() = di.GetFiles()
Console.WriteLine("The following files exist in the current
directory:")
' Print out the names of the files in the current directory.
Dim fiTemp As FileInfo
For Each fiTemp In fi
Console.WriteLine(fiTemp.Name)
Next fiTemp

http://msdn.microsoft.com/en-us/libr...info.name.aspx

Hope this helps
Nov 10 '08 #4

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

Similar topics

7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
23
by: paul | last post by:
HI! How so get the name of the present page into a variable? I need it because I need to attach it to a path so I can make others link to me. My pages are in iframes. Paul
6
by: markoniinimaki | last post by:
Hi, suppose I get a document name a.xml and a path //foo/bar (which nodes eventually to read from it) from another doc. Problem: how to combine them so that the whole expression gets...
10
by: Ben Finney | last post by:
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to...
8
by: Finger.Octopus | last post by:
Hi, Well, I want to read the contents of file in a character array. Actually, I am doing this for Hangman(game). I want to read the contents of file in a character array, so that I can pick a...
12
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
9
by: Bill David | last post by:
I know it's very strange to do that since we have the file name when we call: int open(const char *pathname, int oflag,...); And we can store the file name for later usage. But I just wonder if...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.