-5

I have files in a folder.

Filenames in this folder are available in a .csv file's column B.

Column A contains new file name.

Eg,

Attached pic. enter image description here

How do I rename files in the folder based on column A using VB.NET ?

vicki
  • 157
  • 2
  • 23
  • 2
    What have you tried? There are lots of resources on how to do this type of thing if you do a quick search: http://stackoverflow.com/questions/1898/csv-file-imports-in-net http://stackoverflow.com/questions/10784613/how-to-rename-file-in-vb-net – Neal Nov 29 '16 at 11:40

1 Answers1

0

First you must read the your CSV.. i suppose that is not too big, so do something like

Dim MyCSV() As String = IO.File.ReadAllLines("c:\my file.csv")

Then go ahead with a "For Each" line in your CSV

For Each Line In MyCSV.ToArray

Next

In this For Each you must split the current line.. and i suppose is a standard CSV so must be the "," (i think)

Dim MySplitLine() As String = Line.Split(","c)

Finally (also in the For Each) you can rename your file with the new name

If IO.File.Exists("c:\folder 1\folder 2\" & MySplitLine(1) & ".extension") Then
FileSystem.Rename("c:\folder 1\folder 2\" & MySplitLine(1) & ".extension",
                  "c:\folder 9\folder 8\" & MySplitLine(0) & ".extension")
End If

Dont forget to set your extension.

Tyler
  • 416
  • 4
  • 11