473,394 Members | 1,706 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.

Get only filename from a directory

I get all files from a directory an write it into an
array. Then I want get only the file name with file
extension without the full path.

//code
string[] aFilenames;
Directory.GetFiles(comandline.GetParameterValue
("sDirectory"));

for (int i=0; i < aFilenames.Length; i++)
{
// here I need only the file name!
}
//end code

For example:
sDirectory is "c:\tmp\test\"
and in the 'test' folder are two files:
test1.txt
test2.txt

For the sample I get
aFilesnames[0] = c:\tmp\test\test1.txt
aFilesnames[1] = c:\tmp\test\test2.txt

But I need only
aFilesnames[0] = test1.txt
aFilesnames[1] = test2.txt

Should I work with aFilesnames[i].Remove or something like
that, or which possibilities are there?

Thanks a lot for your assistance.
Nov 15 '05 #1
2 37970
Hi Michael,

Path.GetFileName is what you are looking for :)

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Michael" <mi*****@go-on-line.de> wrote in message
news:04****************************@phx.gbl...
I get all files from a directory an write it into an
array. Then I want get only the file name with file
extension without the full path.

//code
string[] aFilenames;
Directory.GetFiles(comandline.GetParameterValue
("sDirectory"));

for (int i=0; i < aFilenames.Length; i++)
{
// here I need only the file name!
}
//end code

For example:
sDirectory is "c:\tmp\test\"
and in the 'test' folder are two files:
test1.txt
test2.txt

For the sample I get
aFilesnames[0] = c:\tmp\test\test1.txt
aFilesnames[1] = c:\tmp\test\test2.txt

But I need only
aFilesnames[0] = test1.txt
aFilesnames[1] = test2.txt

Should I work with aFilesnames[i].Remove or something like
that, or which possibilities are there?

Thanks a lot for your assistance.

Nov 15 '05 #2
Hi Ignacio,

many thanks for your quick help. It's exactly what I need.

Michael
-----Original Message-----
Hi Michael,

Path.GetFileName is what you are looking for :)

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Michael" <mi*****@go-on-line.de> wrote in message
news:04****************************@phx.gbl...
I get all files from a directory an write it into an
array. Then I want get only the file name with file
extension without the full path.

//code
string[] aFilenames;
Directory.GetFiles(comandline.GetParameterValue
("sDirectory"));

for (int i=0; i < aFilenames.Length; i++)
{
// here I need only the file name!
}
//end code

For example:
sDirectory is "c:\tmp\test\"
and in the 'test' folder are two files:
test1.txt
test2.txt

For the sample I get
aFilesnames[0] = c:\tmp\test\test1.txt
aFilesnames[1] = c:\tmp\test\test2.txt

But I need only
aFilesnames[0] = test1.txt
aFilesnames[1] = test2.txt

Should I work with aFilesnames[i].Remove or something like that, or which possibilities are there?

Thanks a lot for your assistance.

.

Nov 15 '05 #3

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

Similar topics

2
by: Brian Richmond | last post by:
I'm writing a script to upload images along with articles to a directory on the server. I'm developing it offline on my WinXP and Apache 1.3.x laptop and it's working great, but when I move the...
7
by: Hostos | last post by:
Hello All, Please advice...I would like to do this in php, but I am open to suggestions I am going to place about 6 gigs of jpeg pictures on a web server. And. I want to allow a user to go...
6
by: Diego Valencia | last post by:
The attach error was generate when I tried to use invoke method "setpassword" this is mi code objeto.Invoke("SetPassword", new object {contraseƱa}); The error is "The filename, directory...
1
by: Trevor | last post by:
Also posted in general ASP.NET forum. System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. I have hit a problem for which I can find no solutions. Has...
0
by: Don | last post by:
I intermittently get a runtime Compilation Error that says 'The compiler failed with error code 2000'. It appears that a DLL cannot be found in the 'temporary asp.net files' directory. The...
3
by: aidechamp | last post by:
Hi all, is it possible to get a filename directory list of a website (possibly with full path indication)? Using python & possibly wget? Bye.
1
by: jo3c | last post by:
hi everybody im a newbie in python, i have a question how do u parse a bunch of text files in a directory? directory: /dir files: H20080101.txt ,...
8
by: Michael Robertson | last post by:
I'm having trouble opening a file in linux, whose path has spaces in it. $ mkdir my\ test $ echo test my\ test/test.txt $ python Exception Exception but yet...
7
by: sumanta123 | last post by:
Dear Sir when i am getting the value from properties file the the path showing http://127.0.0.1:81/help/Subject of Issue.txt which is right. But in jsp in try block when pass SubjectofIssue path...
0
by: rajib123 | last post by:
I am trying to write a windows utility that downloads some files from an ftp site to a local directory and then uploads those files to another ftp site. The files that I need to download are posted...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.