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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rename files in folder from csv file

Status
Not open for further replies.

toon10

Programmer
Mar 26, 2004
303
DE
Hi

I have a .CSV file with an existing name column and a new name column.

E.G. 3145.pdf, Item 3145.pdf

I want to look at the first column (3145.pdf) find that file in a given directory (c:\temp) and then rename it to the second column (Item 3145.pdf) and then move to the next column until all files in the folder have been renamed.

I came across what I believe is the solution in a VB script only I don’t know how to run the script so I thought I could do similar from within VB6.

Code:
' VBScript source code
Const ForReading = 1

strComputer = "."
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\TEMP\PDF_338-Series_Numbers_from_Alchemy\338-Series_Alchemy_Metadata.txt.csv", ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    arrParts = Split(strLine, ",")
    strFile = "C:\\TEMP\PDF_338-Series_Numbers_from_Alchemy\\" & arrParts(0)
    Set colItems  = objWMIService.ExecQuery _
        ("Select * From CIM_Datafile Where Name = '" & strFile & "'")
    For Each objItem in colItems
        strNewName = "C:\TEMP\PDF_338-Series_Numbers_from_Alchemy\" & arrParts(1)
        objItem.Rename strNewName
    Next
Loop

objFile.Close
 
To run a VBScript file just save it with a filetype of .VBS then double click it

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top