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

Mass change letters in filename 1

Status
Not open for further replies.

Mijjoiji

IS-IT--Management
May 15, 2001
48
SE
I've saved around 1500 files on a crashed computer through Knoppix. The sad thing is that Knoppix changed all the swedish letters ÅÄÖ in the file name into symbols. And since I'm beginner at scripting I don't know where to start, or even if it's possible to mass change the filenames with a script. Could someone guide me a little bit? Maybe there's a tool out there? Have googled for 30 minutes without luck.

Regards
Jim
 

Set aFolder = FSO.GetFolder("c:\folder")

For Each aFile In aFolder.Files
strName = aFile.Name
strName = Replace(strName, "x", "y")
aFile.Name = strName

Next

i think that should work
 
While this may not be the "best" way, this is how I'd do it. I know looping within a loop is generally slow and to be avoided but it runs fast on my box and I couldn't think of a better/easier way. Just set the ProcessFolder var to the folder with the munged files. The Replace var contains ascii values of the characters to fix.. the second "facet" of the replace array determines what character to replace.. #1 is the ascii value to look for, #2 is what to change it to.


Dim Replace(10, 5)
Set FS = CreateObject("Scripting.FileSystemObject")

ProcessFolder = "c:\swedish"
Replace(1, 1) = 197
Replace(1, 2) = 65
Replace(2, 1) = 196
Replace(2, 2) = 66
Replace(3, 1) = 214
Replace(3, 2) = 67

Set Folder = FS.GetFolder(ProcessFolder)
for each File in Folder.Files
for CurChar = 1 to len(File.Name)
for CurArray = 1 to ubound(Replace)
if asc(mid(File.Name, CurChar, 1)) = Replace(CurArray, 1) then tmpVar = tmpVar & chr(Replace(CurArray, 2)): Replaced = True
next
if Not Replaced then tmpVar = tmpVar & mid(File.Name, CurChar, 1) else Replaced = False
next
FS.MoveFile ProcessFolder & "\" & File.Name, ProcessFolder & "\" & tmpVar
tmpVar = ""
next

wscript.echo "Process Complete!"
Set Folder= Nothing: Set FS = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top