|
-
Jul 23rd, 2003, 01:08 PM
#1
Thread Starter
Fanatic Member
files
I am using the code below to get all the files in a particular folder.
There are two questions
1) I would like to get the file names only and not the fullpath on each loop
i.e text1.txt, text2.txt, ...
whereas right now I am getting
C:\Farshad\Net\VB\Files\text1.txt
C:\Farshad\Net\VB\Files\text2.txt
...
2) instead of using the path ("C:\Farshad\Net\VB\Files\") I would like to use the path on a web server such as
"http://www.test1.com/images"
can this be done?
Thanks
Dim d() As String
d = System.IO.Directory.GetFiles("C:\Farshad\Net\VB\Files\")
Dim en As System.Collections.IEnumerator
en = d.GetEnumerator
While en.MoveNext
Console.WriteLine(CStr(en.Current))
End While
-
Jul 24th, 2003, 02:35 AM
#2
I can't help with question 2, but this is what I've done in the past for question 1.
The first line strips off the path, the second line strips off the extension.
VB Code:
strFormatFileName = strFile.Substring(InStrRev(strFile, "\"))
strFormatFileName = strFormatFileName.Substring(0, InStr(strFormatFileName, ".") - 1)
To tie this up with your code, strFile is (for example) d(1) and strFormatFileName is what you want to output.
Oh, just done some more research, you may be able to do it much more elegantly by using
VB Code:
Path.GetFileName(CStr(en.Current))
This world is not my home. I'm just passing through.
-
Jul 24th, 2003, 07:15 AM
#3
Sleep mode
1st Question : Here is elegant way .It gets only file name in particular folder .
VB Code:
Dim dir As New IO.DirectoryInfo("c:\windows")
Dim fils() As IO.FileInfo = dir.GetFiles()
Dim i As Integer
For i = 0 To fils.Length - 1
ListBox1.Items.Add(fils(i).Name)
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|