Jump to content

[Help] Replace letters in file names


JohnS
 Share

Recommended Posts

Hi,

I have a big request for all of you that is beyond my knowledge of Autoit (past, present and future).

I helped a friend to recover some files from a dead computer.

What I did was boot from a floppy, used NTFSDOS and copied the files he wanted to another partition. Then formatted the primary partition.

Now we can have access to the recovered files.

The problem is that the file names are in portuguese and with a lot of "ã", "é", "ó", "ç" in it.

So, instead of relação.doc we have relaÆo.doc

My friend will have to rename by hand all of the file with replaced characters.

Then I though on Autoit.

I found that "Because AutoIt lacks a "FileRename" function, use FileMove to rename a file!"

Then I searched for some ideas that I could adapt, but could not find anything: 1, 2, 3.

So I ask for your help:

Can a script that looks for all the files inside a folder and replaces certain characters in the file name for other characters be done, without touching the correct letters?

The characters to be replace always mean the same, e.g., "" is always "ç", but are not in the same place of the name, e.g., relaÆo (relação - relation) and acÆo (acção - action).

I would appreciate your help, because I only use Autoit to help my unattended installation of Windows and could never do this by myself.

Thank you

Link to comment
Share on other sites

  • Developers

Hi,

I have a big request for all of you that is beyond my knowledge of Autoit (past, present and future).

I helped a friend to recover some files from a dead computer.

What I did was boot from a floppy, used NTFSDOS and copied the files he wanted to another partition. Then formatted the primary partition.

Now we can have access to the recovered files.

The problem is that the file names are in portuguese and with a lot of "ã", "é", "ó", "ç" in it.

So, instead of relação.doc we have relaÆo.doc

My friend will have to rename by hand all of the file with replaced characters.

Then I though on Autoit.

I found that "Because AutoIt lacks a "FileRename" function, use FileMove to rename a file!"

Then I searched for some ideas that I could adapt, but could not find anything: 1, 2, 3.

So I ask for your help:

Can a script that looks for all the files inside a folder and replaces certain characters in the file name for other characters be done, without touching the correct letters?

The characters to be replace always mean the same, e.g., "" is always "ç", but are not in the same place of the name, e.g., relaÆo (relação - relation) and acÆo (acção - action).

I would appreciate your help, because I only use Autoit to help my unattended installation of Windows and could never do this by myself.

Thank you

Sure, first of all FileMove is indeed the way to rename a file.

Here is something to get you started :

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    $filenew = $file
    $fileNew = StringReplace($fileNew,"Æ","çã")
    $fileNew = StringReplace($fileNew,"??","??")
    $fileNew = StringReplace($fileNew,"??","??")
    If $file <> $filenew then FileMove($file,$filenew)
WEnd

; Close the search handle
FileClose($search)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thank you so much, JdeB.

I have had the time to test your script and it works perfectly.

You have just saved us some hours renaming and correcting file names.

;):lmao:

I could never write something so complex like this. I mean, I can read it and sort of understand it, but not in a way that I can reproduce it.

Just one other request:

Is it possible to perform the operation in all the subfolder of the folder where the script is?

I ask this because we have 27 subfolders and that will mean that we have to copy the script 27 times and exectute it 27 times.

Again, thank you so much.

Link to comment
Share on other sites

  • Developers

Thank you so much, JdeB.

I have had the time to test your script and it works perfectly.

You have just saved us some hours renaming and correcting file names.

;):lmao:

I could never write something so complex like this. I mean, I can read it and sort of understand it, but not in a way that I can reproduce it.

Just one other request:

Is it possible to perform the operation in all the subfolder of the folder where the script is?

I ask this because we have 27 subfolders and that will mean that we have to copy the script 27 times and exectute it 27 times.

Again, thank you so much.

sure its possible ... but its more complex so not sure if you are better of copying the above script 27 times.

here is an untested version that should be close ... it will also log the peformed renames to rename.log.

Dim $n_Dirnames[200000]    ; max number of directories that can be counted
$T_Dir = "c:\target Directory"
;
$n_DirCount = 0
$n_File = ""
$n_Search = ""
$File = ""
$T_DirCount = 1
; remove the end \
If StringRight($T_Dir, 1) = "\" Then $T_Dir = StringTrimRight($T_Dir, 1)
$n_Dirnames[$T_DirCount] = $T_Dir
; Exit if base dir doesn't exists
If Not FileExists($T_Dir) Then Exit 0
; keep on looping untill all directories are counted
While $T_DirCount > $n_DirCount
    $n_DirCount = $n_DirCount + 1
    $n_Search = FileFindFirstFile($n_Dirnames[$n_DirCount] & "\*.*")
    If $n_Search = -1 Then
        ContinueLoop
    EndIf
    While 1
        $n_File = FileFindNextFile($n_Search)
        If @error Then ExitLoop
        $File = $n_Dirnames[$n_DirCount] & "\" & $n_File
        ; if Directory than add to the list of directories to be processed
        If StringInStr(FileGetAttrib($File), "D") > 0 Then
            If $T_Excl_SubDir = 0 Then
                $T_DirCount = $T_DirCount + 1
                $n_Dirnames[$T_DirCount] = $File
            EndIf
        Else
            ; Chech if file needs to be renamed
            $FileNew = $File
            $FileNew = StringReplace($FileNew, "Æ", "çã")
            $FileNew = StringReplace($FileNew, "??", "??")
            $FileNew = StringReplace($FileNew, "??", "??")
            If $File <> $FileNew Then
                FileMove($n_Dirnames[$n_DirCount] & "\" & $File, $n_Dirnames[$n_DirCount] & "\" & $FileNew)
                FileWriteLine(@ScriptDir & "\rename.log", "Renamed:" & $n_Dirnames[$n_DirCount] & "\" & $File & " to " & $n_Dirnames[$n_DirCount] & "\" & $FileNew)
            EndIf
        EndIf
    WEnd
    FileClose($n_Search)
WEnd
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thank you, JdeB, but the second script isn't working.

It doesn't replace any letter in the folder of the script nor in the subfolders.

I can't tell what's wrong because it's to advanced for me.

Before your second reply I tried to make something of mine with your first script, the one that replaces letters in the files that are in the same folder of the script.

And, as I said, we have 27 subfolders to replace.

So, instead of copying the script 27 times, I added this portion to the begining of your first script:

$search = FileSelectFolder("Choose a folder.", "")

If @error Then

MsgBox(4096,"","No folder chosen")

Else

; Begining of JdeB script

Becoming this:

$search = FileSelectFolder("Choose a folder.", "")

If @error Then

MsgBox(4096,"","No folder chosen")

Else

; Begining of JdeB script

;Shows the filenames of all files in the current directory.

$search = FileFindFirstFile("*.*")

EndIf

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

$filenew = $file

$fileNew = StringReplace($fileNew,"þ","ç")

$fileNew = StringReplace($fileNew,"ß","á")

$fileNew = StringReplace($fileNew,"Ú","é")

$fileNew = StringReplace($fileNew,"¾","ó")

$fileNew = StringReplace($fileNew,"Ò","ã")

$fileNew = StringReplace($fileNew,"Ý","í")

$fileNew = StringReplace($fileNew,"-","Í")

If $file <> $filenew then FileMove($file,$filenew)

WEnd

; Close the search handle

FileClose($search)

But it doesn't work.

Even if I select a folder the script only replaces letters of the files next to the script.

To my knowledge it should work, because I created a variable that represents a chosen folder and that passes to the next code (yours). The variable is the same as yours: $search.

Damn newby ;)

Link to comment
Share on other sites

  • Developers

Think i see a error in my posted script..

It will not rename directory names, just filenames.

try this version:

Dim $n_Dirnames[200000]    ; max number of directories that can be counted
$T_Dir = "c:\target Directory"
;
$n_DirCount = 0
$n_File = ""
$n_Search = ""
$File = ""
$T_DirCount = 1
; remove the end \
If StringRight($T_Dir, 1) = "\" Then $T_Dir = StringTrimRight($T_Dir, 1)
$n_Dirnames[$T_DirCount] = $T_Dir
; Exit if base dir doesn't exists
If Not FileExists($T_Dir) Then Exit 0
; keep on looping untill all directories are counted
While $T_DirCount > $n_DirCount
    $n_DirCount = $n_DirCount + 1
    $n_Search = FileFindFirstFile($n_Dirnames[$n_DirCount] & "\*.*")
    If $n_Search = -1 Then
        ContinueLoop
    EndIf
    While 1
        $n_File = FileFindNextFile($n_Search)
        If @error Then ExitLoop
        $File = $n_Dirnames[$n_DirCount] & "\" & $n_File
        ; if Directory than add to the list of directories to be processed
        If StringInStr(FileGetAttrib($File), "D") > 0 Then
            $T_DirCount = $T_DirCount + 1
            $n_Dirnames[$T_DirCount] = $File
        Else
            ; Chech if file needs to be renamed
            $FileNew = $n_File
            $FileNew = StringReplace($FileNew, "Æ", "çã")
            $FileNew = StringReplace($FileNew, "??", "??")
            $FileNew = StringReplace($FileNew, "??", "??")
            If $File <> $FileNew Then
                FileMove($n_Dirnames[$n_DirCount] & "\" & $File, $n_Dirnames[$n_DirCount] & "\" & $FileNew)
                FileWriteLine(@ScriptDir & "\rename.log", "Renamed:" & $n_Dirnames[$n_DirCount] & "\" & $File & " to " & $n_Dirnames[$n_DirCount] & "\" & $FileNew)
            EndIf
        EndIf
    WEnd
    FileClose($n_Search)
WEnd
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Becoming this:But it doesn't work.

Even if I select a folder the script only replaces letters of the files next to the script.

To my knowledge it should work, because I created a variable that represents a chosen folder and that passes to the next code (yours). The variable is the same as yours: $search.

Damn newby ;)

you need to change to the selected directory:

$searchFolder = FileSelectFolder("Choose a folder.", "")
If @error Then
    MsgBox(4096, "", "No folder chosen")
Else
    ; Begining of JdeB script
    ;Shows the filenames of all files in the current directory.
    FileChangeDir($searchFolder)
    $search = FileFindFirstFile("*.*")
EndIf
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf


While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $filenew = $file
    $filenew = StringReplace($filenew, "þ", "ç")
    $filenew = StringReplace($filenew, "ß", "á")
    $filenew = StringReplace($filenew, "Ú", "é")
    $filenew = StringReplace($filenew, "¾", "ó")
    $filenew = StringReplace($filenew, "Ò", "ã")
    $filenew = StringReplace($filenew, "Ý", "í")
    $filenew = StringReplace($filenew, "-", "Í")
    If $file <> $filenew Then FileMove($file, $filenew)
WEnd

; Close the search handle
FileClose($search)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

No, the script for subfolders is not working. ;):lmao:

For testing puposes, I upload a .zip file with some files in various subfolders for those of you that are so kind to test with it.

To make it easier, these are the letters I want to repalce:

$FileNew = StringReplace($FileNew,"þ","ç")

$FileNew = StringReplace($FileNew,"ß","á")

$FileNew = StringReplace($FileNew,"Ú","é")

$FileNew = StringReplace($FileNew,"¾","ó")

$FileNew = StringReplace($FileNew,"Ò","ã")

$FileNew = StringReplace($FileNew,"Ý","í")

$FileNew = StringReplace($FileNew,"-","Í")

Thanks

Testing_files.zip

Edited by JohnS
Link to comment
Share on other sites

  • Developers

Yep, there was a problem ..

Tested with your files and look ok now:

Dim $n_Dirnames[200000]    ; max number of directories that can be counted
$T_Dir = "C:\Temp\Testing_files"
;
$n_DirCount = 0
$n_File = ""
$n_Search = ""
$File = ""
$T_DirCount = 1
; remove the end \
If StringRight($T_Dir, 1) = "\" Then $T_Dir = StringTrimRight($T_Dir, 1)
$n_Dirnames[$T_DirCount] = $T_Dir
; Exit if base dir doesn't exists
If Not FileExists($T_Dir) Then Exit 0
; keep on looping untill all directories are counted
While $T_DirCount > $n_DirCount
    $n_DirCount = $n_DirCount + 1
    $n_Search = FileFindFirstFile($n_Dirnames[$n_DirCount] & "\*.*")
    If $n_Search = -1 Then
        ContinueLoop
    EndIf
    While 1
        $n_File = FileFindNextFile($n_Search)
        If @error Then ExitLoop
        $File = $n_Dirnames[$n_DirCount] & "\" & $n_File
        ; if Directory than add to the list of directories to be processed
        If StringInStr(FileGetAttrib($File), "D") > 0 Then
            $T_DirCount = $T_DirCount + 1
            $n_Dirnames[$T_DirCount] = $File
        Else
            ; Chech if file needs to be renamed
            $FileNew = $n_File
            $FileNew = StringReplace($FileNew,"þ","ç")
            $FileNew = StringReplace($FileNew,"ß","á")
            $FileNew = StringReplace($FileNew,"Ú","é")
            $FileNew = StringReplace($FileNew,"¾","ó")
            $FileNew = StringReplace($FileNew,"Ò","ã")
            $FileNew = StringReplace($FileNew,"Ý","í")
            $FileNew = StringReplace($FileNew,"-","Í")
            If $File <> $FileNew Then
                FileMove($File, $n_Dirnames[$n_DirCount] & "\" & $FileNew)
                FileWriteLine(@ScriptDir & "\rename.log", "Renamed:" & $File & @LF & "     to:" & $n_Dirnames[$n_DirCount] & "\" & $FileNew)
            EndIf
        EndIf
    WEnd
    FileClose($n_Search)
WEnd

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Sorry JdeB, I don't know what's happening, but the script isn't working for me. Nothing gets changed.

For testing purposes I added

; Good bye

MsgBox(0, "", "Work is done")

to the end of your script, but the message never appears.

The script ends immediately after started, without doing anything.

Am I doing something wrong?

Thanks

Edited by JohnS
Link to comment
Share on other sites

  • Moderators

I don't have any of the characters in the file you showed to replace, so this I guess goes to you untested. Are you sure you're replacing the right characters? Because I only replaced 1 or 2 of them I think.

_FileConvertText(@DesktopDir & '\Trabalho Final\')

Func _FileConvertText($hDirectory, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = True)
    If Not StringRight($hDirectory, 1) = '\' Then $hDirectory &= '\'
    Local $aAllFilesFolders = _FileListToArrayEx($hDirectory, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = True)
    If @error Or Not IsArray($aAllFilesFolders) Then Return SetError(1, 0, 0)
    Local $sFileNew
    For $iCC = 1 To UBound($aAllFilesFolders) - 1
        $sFileNew = $aAllFilesFolders[$iCC]
        $sFileNew = StringReplace($sFileNew,"þ","ç")
        $sFileNew = StringReplace($sFileNew,"ß","á")
        $sFileNew = StringReplace($sFileNew,"Ú","é")
        $sFileNew = StringReplace($sFileNew,"¾","ó")
        $sFileNew = StringReplace($sFileNew,"Ò","ã")
        $sFileNew = StringReplace($sFileNew,"Ý","í")
        $sFileNew = StringReplace($sFileNew,"-","Í")
        If $sFileNew <> $aAllFilesFolders[$iCC] Then
            FileMove($aAllFilesFolders[$iCC], $sFileNew, 1)
        EndIf
    Next
    Return 1
EndFunc
    

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        Local $iPid
        If Not $iRecurse Then
            $iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC] & '" /b /o-e /od', '', @SW_HIDE, 6)
        Else
            $iPid = Run(@Comspec & ' /c dir /b /s /a "' & $sPath & '\' & $aSplit[$iCC] & '"', '', @SW_HIDE, 6)
        EndIf
        While 1
            $sRead &= StdoutRead($iPid)
            If @error Then ExitLoop
        WEnd
    Next
    If StringStripWS($sRead, 8) = '' Then Return SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft(StringTrimLeft($aFSplit[$iCC], StringInStr($aFSplit[$iCC], '\', 0, -1)), _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 1
                If StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 2
                If Not StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc
Anyway, see if that helps.

Edit:

Removed a redundant msgbox... and a redundant filedelete.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

After looking at SmOke_N script, I noticed it's first line.

Then I realized what I was doing wrong.

To run JdeB's script I had to place my files under "C:\Temp\Testing_files" and run the script from there.

My files were elsewhere.

So I put them on the right folder.

And I ran the script.

And it worked.

But it seems it worked better than well.

It seems it has looked for files in the entire C: partition.

Then it renamed some system files and now my Windows doesn't load.

It created a 40 MB log file, with 262810 lines, some lines like this:

Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\monitor8.inf
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\monitor8.inf
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\monitor8.PNF
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\monitor8.PNF
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\moviemk.inf
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\moviemk.inf
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\moviemk.PNF
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\moviemk.PNF
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpe.inf
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpe.inf
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpe.PNF
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpe.PNF
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mplayer2.inf
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mplayer2.inf
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mplayer2.PNF
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mplayer2.PNF
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpsstln.inf
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpsstln.inf
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpsstln.PNF
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mpsstln.PNF
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mqsysoc.inf
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mqsysoc.inf
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mqsysoc.PNF
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mqsysoc.PNF
Renamed:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mscpqpa1.inf
     to:C:\Temp\Testing_files\..\.\..\WINDOWS\inf\.\mscpqpa1.inf

Well, next time I will test my scripts under Virtual PC.

Get to go now, and see if I can understand what went wrong.

Link to comment
Share on other sites

Hi, I am back after a disk format ;) .

And it't just to announce that all my problems are solved :evil:

I have found what went wrong with Jdeb script: I compiled it with Autoit version 3.1.1, which was the version I had installed.

After the format I installed the latest version, compiled the script, tested it (in a virtual machine, just in case :lmao: ) et voilá, it worked just as JdeB did it would.

So here is the final version, which allows one to choose the starting folder and works all subfolders.

$T_Dir = FileSelectFolder("Choose a folder.", "")

If @error Then

MsgBox(4096, "", "No folder chosen")

Exit

Else

FileChangeDir($T_Dir)

; Begining of JdeB script

Dim $n_Dirnames[200000]; max number of directories that can be counted

;

$n_DirCount = 0

$n_File = ""

$n_Search = ""

$File = ""

$T_DirCount = 1

; remove the end \

If StringRight($T_Dir, 1) = "\" Then $T_Dir = StringTrimRight($T_Dir, 1)

$n_Dirnames[$T_DirCount] = $T_Dir

; Exit if base dir doesn't exists

If Not FileExists($T_Dir) Then Exit 0

; keep on looping untill all directories are counted

While $T_DirCount > $n_DirCount

$n_DirCount = $n_DirCount + 1

$n_Search = FileFindFirstFile($n_Dirnames[$n_DirCount] & "\*.*")

If $n_Search = -1 Then

ContinueLoop

EndIf

While 1

$n_File = FileFindNextFile($n_Search)

If @error Then ExitLoop

$File = $n_Dirnames[$n_DirCount] & "\" & $n_File

; if Directory than add to the list of directories to be processed

If StringInStr(FileGetAttrib($File), "D") > 0 Then

$T_DirCount = $T_DirCount + 1

$n_Dirnames[$T_DirCount] = $File

Else

; Chech if file needs to be renamed

$FileNew = $n_File

$FileNew = StringReplace($FileNew,"þ","ç")

$FileNew = StringReplace($FileNew,"ß","á")

$FileNew = StringReplace($FileNew,"Ú","é")

$FileNew = StringReplace($FileNew,"¾","ó")

$FileNew = StringReplace($FileNew,"Ò","ã")

$FileNew = StringReplace($FileNew,"Ý","í")

$FileNew = StringReplace($FileNew,"-","Í")

If $File <> $FileNew Then

FileMove($File, $n_Dirnames[$n_DirCount] & "\" & $FileNew)

FileWriteLine(@ScriptDir & "\rename.log", "Renamed:" & $File & @LF & " to:" & $n_Dirnames[$n_DirCount] & "\" & $FileNew)

EndIf

EndIf

WEnd

FileClose($n_Search)

WEnd

; End of JdeB script

; Good bye

MsgBox(0, "", "Work is done")

I also tested SmOke_N script but it gives me plenty of errors with syntax check.

Thank you both.

JS

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...