Learn when you want, where you want with convenient online training courses. Sign up now!
[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
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
Open in new window
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
SaveFilenamesToFile("C:\Working Directory", "C:\Working Directory\Test", "Filename.txt")
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.