Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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;;

Posted

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"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...