carbcycle Posted May 12, 2005 Posted May 12, 2005 Hi, Wonder if you could help me. I�m trying to create a text file with file names found in a directory and then add various characters. This works fine however I really don�t want the directory location inserted in the file, only need the file name. Is there anyway of manipulating my code to do this? Here is the code: ' Specify the directories you want to manipulate. Dim d() As String d = System.IO.Directory.GetFiles(StartForm.pdfloc) Dim en As System.Collections.IEnumerator en = d.GetEnumerator ' Create an instance of StreamWriter to write text to a file. Dim sw As StreamWriter = New StreamWriter(StartForm.pdfloc & "\metadata" & StartForm.company & ".txt") While en.MoveNext ' Add file info to text file sw.WriteLine(en.Current & ";" & StartForm.company & ";;") End While 'Close write sw.Close() This is what the code produces: C:\Software\AD Tool\adi15.exe;202;; C:\Software\AD Tool\adi20.exe;202;; Quote
Administrators PlausiblyDamp Posted May 12, 2005 Administrators Posted May 12, 2005 Easiest way is to use the Path class in System.IO Dim s as String s = System.IO.Path.GetFileName("c:\test\test.txt") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JumpyNET Posted May 13, 2005 Posted May 13, 2005 Another solution You can also manipulate the string. It's not as short as GetFileName but you might find these functions useful in other situations as well. Dim TempString As String, FileName As String Dim FullPath As String = "C:\My Folder\My File.txt" TempString = StrReverse(FullPath) 'Returns "txt.eliF yM\redloF yM\:C" TempString = Split(TempString, "\")(0) 'Returns "txt.eliF yM" FileName = StrReverse(TempString) 'Returns "My File.txt" Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.