Below code absolutely worked for me to update the file extension.
Example: abc.pdf to abc.txt
Filepath = "Pls mention your Filepath" Set objFso = CreateObject("Scripting.FileSystemObject") '' Below line of code is to get the object for Folder where list of files are located Set objFolder = objFso.GetFolder(Filepath) '' Below line of code used to get the collection object to hold list of files located in the Filepath. Set FileCollection = objFolder.Files For Each file In FileCollection WScript.Echo "File name ->" + file.Name ''Instr used to Return the position of the first occurrence of "." within the File name s = InStr(1, file.Name, ".",1) WScript.Echo s WScript.Echo "Extn --> " + Mid(file.Name, s, Len(file.Name)) 'Left(file.Name,s-1) = Used to fetch the file name without extension ' Move method is used to move the file in the Desitnation folder you mentioned file.Move(Filepath & Left(file.Name,s-1)&".txt") Next
Venkata suresh
source share