Hello there!
Sorry to resurrect this thread again, but after a while using this script, I started noticing some inconsistent behavior that I hadn't seen before. I compared the code I am actually using with the one you posted here, but I couldn't spot any differences that could cause the problems I am seeing.
Issue 1)
The problem happens when I try to apply the renamer to a file that already has the exact same Prefix I wish to append. On the last version of the script, you added a check to see if the prefix was already there to prevent it from being appended twice. From what I remember, it was working fine, but I hadn't tried to rename a file that already had the intended prefix for a while until now. When I tried doing it again, I am now receiving an error message saying that there was a problem on line 25 and asking if I want to stop or continue running the script. Here's line 25:
Code: Select all
sel.item(A_Index-1).name := Newfilename
Was that what you intended when you added the check to see if the prefix to be appended was already there? I don't remember seeing this message in the past, but I don't know if I just didn't run into any instances in which the prefix was already appended. In my mind, the script would simply not append the prefix and move on to the next file.
Issue 2)
This one is a little trickier because I can't always reproduce it. There are some cases in which I run the script and, instead of renaming the file as expected, it actually renames the file exactly as another file in the folder, so much so that windows prompts me to name it as "Filename (1)" because there already is another file in the folder with the same name. This is particularly worrying, since it could ruin the database with incorrectly named files if people using the script don't know what's going on. This is further confirmed by the fact that sometimes windows even asks me if I want to change the file's extension.
Here is the actual version I am using. I added some characters to be replaced in oWord and made some comments in the code for my coworkers to remember where they have to edit when changing the prefix, but otherwise the code is unaltered, as far as I can tell:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
oWord := {"à":"a", "á":"a", "ã":"a", "â":"a", "é":"e", "è":"e", "ê":"e"
, "í":"i", "ì":"i", "ó":"o", "õ":"o", "ô":"o", "ò":"o", "ú":"u"
, "ù":"u", "ç":"c", "À":"A", "Á":"A", "Ã":"A", "Â":"A", "É":"E"
, "Ê":"E", "È":"E", "Í":"I", "Ì":"I", "Ó":"O", "Õ":"O", "Ô":"O"
, "Ò":"O", "Ú":"U", "Ù":"U", "Ç":"C", "��":"ca", "_-_":"_", "__":"_"}
return
F7::
shellWindows := ComObjCreate("Shell.Application").Windows()
win := shellWindows.Item(0)
sel := win.Document.SelectedItems()
loop % sel.Count
{
if !RegExMatch(sel.item(A_Index-1).name, "^Longchamp_") ;<========== INSERIR AQUI PREFIXO (NOME DO CLIENTE SEGUIDO DE UNDERLINE "_")
Newfilename := "Longchamp_" sel.item(A_Index-1).name ;<========== INSERIR AQUI PREFIXO (NOME DO CLIENTE SEGUIDO DE UNDERLINE "_"
Newfilename := StrReplace(Newfilename, " ", "_")
for k, v in oWord
Newfilename := StrReplace(Newfilename, k, v)
Newfilename := StrReplace(Newfilename, "�", "_")
sel.item(A_Index-1).name := Newfilename
}
shellWindows := ""
return