-1

I'm making a small application in Visual Basic using Studio 2015, and I'd like to know how I can rename all the files in the desktop to test1.txt, test2.txt and so on. I know already how to find the current user desktop directory, but I have no idea how to rename all files from there. Thanks!

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • rename all of the files into the same name? I guess something is missing in your question. – A.S.H Jan 18 '17 at 06:15
  • 1
    [**To get all the files in directory**](http://stackoverflow.com/questions/1457525/get-a-list-of-all-files-inside-of-a-directory-in-vb-net) and [**To rename a file**](http://stackoverflow.com/questions/10784613/how-to-rename-file-in-vb-net) – Vivek S. Jan 18 '17 at 07:21
  • There are plenty of examples on the internet on how to rename files. – Bugs Jan 18 '17 at 07:22

1 Answers1

0

With Directory.Getfiles you can get all files in a specific folder (in your case your desktop).

All you have todo now is to rename each file in your array.

My.Computer.FileSystem.RenameFile("C:\Test.txt", "SecondTest.txt")

You can realize that with a for each that iterates though your array of files of your desktop. The name test{i} can be also build with the for each.

Lars Crown
  • 216
  • 1
  • 5