Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic 2008- Move all text files to Desktop "Text folder"

Status
Not open for further replies.

msean123

Technical User
Feb 13, 2011
2
US
I want to create a program that I can create a Text file folder on my desktop and move all the text files into the folder.

Here is what I have so far:

Below is where I create the Text folder:

Dim myPath As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "Text")
IO.Directory.CreateDirectory(myPath)

Here is where I am trying to move all of the .txt files to the new Text folder:

For Each foundFile As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
FileIO.SearchOption.SearchTopLevelOnly, "*.txt")

Here is where the error is: It won't do it...
My.Computer.FileSystem.MoveFile(foundFile, myPath & "/" & foundFile)

Next

Do you have any tips for moving the .txt files to the Text folder?


 
This could simply be erring on one file/folder...folder being my guess. Use a Try/Catch, with it writing a file of all files that aren't copied.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Thanks RonRepp,

But I tested this on my desktop with just one .txt file and the file did not move.

What do you mean by "writing a file of all files that aren't copied"?

The file is already sitting on my desktop and in the Sub I have already created the folder.

All need is the right method to move the file without using a known path (i.e. C/:text.txt). The folder is called "Text" and the files are being found in the For each Loop:

For Each foundFile As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
FileIO.SearchOption.SearchTopLevelOnly, "*.txt")

The files are called: "foundFile". This For each Loop was found on Microsoft's website. I just want to manipulate the next line or two of code to put "foundFile" (s) in the Text folder on my desktop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top