DecodeFileName неплохо работает, но игнорирует ИМЕНА папок. В сами папки заходит (при наличии ключа /s), но их имена игнорирует.
Переименовывает он только файлы с "процентами" в именах - URLEncoded, просто UTF-8 не трогает.
Утилита от DV deutf8.c наоборот, трогает имена UTF-8, но не трогает URLEncoded. Работает тоже хорошо.
Добавлю бинарник в аттач для тех, кому некогда заморачиваться с компиляцией.
Обе утилиты консольные. Не плагин, но всеж куда удобнее без "лишних движений мышкой" при работе из-под FAR.
Обе задачи сразу решаются в рамках Renamer.
Скрипт от DV решает проблему с именами UTF-8,
А следующий скрипт от Denis Kozlov, найденный на
den4b.com,
решает проблему с именами URLEncoded
Code: Select all
function URLDecode(const S: AnsiString; out Output: AnsiString): Boolean;
var
Idx: Integer; // loops thru chars in string
Hex: string; // string of hex characters
Code: Integer; // hex character code (-1 on error)
begin
// Intialise result and string index
Result := False;
Output := '';
Idx := 1;
// Loop thru string decoding each character
while Idx <= Length(S) do
begin
case S[Idx] of
'%':
begin
// % should be followed by two hex digits - exception otherwise
if Idx <= Length(S) - 2 then
begin
// there are sufficient digits - try to decode hex digits
Hex := S[Idx+1] + S[Idx+2];
Code := StrToIntDef('$' + Hex, -1);
Idx := Idx + 2;
end
else
// insufficient digits - error
Code := -1;
// check for error and raise exception if found
if Code = -1 then Exit;
// decoded OK - add character to result
Output := Output + Chr(Code);
end;
'+':
// + is decoded as a space
Output := Output + ' '
else
// All other characters pass thru unchanged
Output := Output + S[Idx];
end;
Inc(Idx);
end;
Result := True;
end;
var
Encoded, Decoded: AnsiString;
begin
Encoded := WideToAnsi(FileName);
if URLDecode(Encoded, Decoded) then
FileName := UTF8Decode(Decoded)
else
FileName := '***ERROR***';
end.
Ради одного файла, конечно, запускать Renamer и долго тыкать мышкой все настраивая весьма избыточные затраты времени. но если файлов много, то можно все переименовать за 1-2 прохода.
Варианты URLEncode, кстати бывают разные
http://www.php.su/urlencode%28%29
Стандартный вариант регламентируется RFC1738.
Есть вариант, где пробелы "традиционно" заменяются на + (плюсы).