Your technology certification is waiting. Enroll in Cloud Class ®
Private Sub SaveFilenamesToFile(ByVal sourceDir As String, ByVal destDir As String, ByVal saveFileAs As String)
'' Make sure that the Source Directory does exist
If Not Directory.Exists(sourceDir) Then
MessageBox.Show("Source Directory " + sourceDir + " Doest Not Exist")
'' Make sure that the Destination Directory does exist
If Not Directory.Exists(destDir) Then
MessageBox.Show("Destination Directory " + destDir + " Doest Not Exist")
'' Get the DirectoryInfo for the source directory
Dim sDir = FileIO.FileSystem.GetDirectoryInfo(sourceDir)
'' Get an array of FileInfo in the directory
Dim names = sDir.GetFiles("*")
'' Create / open the destination file
Dim fs = File.Open(destDir & "\" & saveFileAs, FileMode.OpenOrCreate, FileAccess.Write)
'' Get a stream writer
Dim sw As New StreamWriter(fs)
'' Writes the directiory name as the first line in the file
sw.WriteLine("Directory " + destDir)
'' Write all the file names to the file stream
For Each name As FileInfo In names
'' Clean up
Open in new window
SaveFilenamesToFile("C:\Working Directory", "C:\Working Directory\Test", "Filename.txt")
Dim dir As New IO.DirectoryInfo(Directory.GetCurrentDirectory())
Using sw As StreamWriter = New StreamWriter(Path.Combine(dir.FullName, "files.txt"))
Dim files As IO.FileInfo() = dir.GetFiles()
For Each file In files
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.