ADD: Remove files/folders with overlong names

This commit is contained in:
Alexander Koblov 2016-08-17 18:31:00 +00:00
commit bbd5a6812b
4 changed files with 9 additions and 9 deletions

View file

@ -919,7 +919,7 @@ end;
function mbDeleteFile(const FileName: String): Boolean;
{$IFDEF MSWINDOWS}
begin
Result:= Windows.DeleteFileW(PWideChar(UTF8Decode(FileName)));
Result:= Windows.DeleteFileW(PWideChar(UTF16LongName(FileName)));
end;
{$ELSE}
begin
@ -1155,7 +1155,7 @@ end;
function mbRemoveDir(const Dir: String): Boolean;
{$IFDEF MSWINDOWS}
begin
Result:= RemoveDirectoryW(PWideChar(UTF8Decode(Dir)));
Result:= RemoveDirectoryW(PWideChar(UTF16LongName(Dir)));
end;
{$ELSE}
begin

View file

@ -33,7 +33,7 @@ uses
Converts file name in UTF-8 encoding to file name
with UTF-16 encoding with extended-length path prefix
}
function UnicodeLongName(const FileName: String): UnicodeString;
function UTF16LongName(const FileName: String): UnicodeString;
{en
Enable a privilege
@ -53,7 +53,7 @@ implementation
uses
JwaAclApi, JwaWinNT, JwaAccCtrl, JwaWinBase, JwaWinType;
function UnicodeLongName(const FileName: String): UnicodeString;
function UTF16LongName(const FileName: String): UnicodeString;
begin
if Pos('\\', FileName) = 0 then
Result := '\\?\' + UTF8Decode(FileName)

View file

@ -1279,7 +1279,7 @@ end;
procedure TOSWatch.CreateHandle;
{$IF DEFINED(MSWINDOWS)}
begin
FHandle := CreateFileW(PWideChar(UnicodeLongName(FWatchPath)),
FHandle := CreateFileW(PWideChar(UTF16LongName(FWatchPath)),
FILE_LIST_DIRECTORY,
CREATEFILEW_SHAREMODE,
nil,

View file

@ -3,7 +3,7 @@
-------------------------------------------------------------------------
This unit contains UTF8 versions of Find(First, Next) functions and other stuff
Copyright (C) 2006-2010 Koblov Alexander (Alexx2000@mail.ru)
Copyright (C) 2006-2016 Alexander Koblov (alexx2000@mail.ru)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@ -77,7 +77,7 @@ implementation
uses
LazUTF8, uDebug
{$IFDEF MSWINDOWS}
, uMyWindows
, DCWindows, uMyWindows
{$ENDIF}
{$IFDEF UNIX}
, Unix, DCOSUtils, DCFileAttributes, DCConvertEncoding, uMyUnix
@ -133,9 +133,9 @@ end;
function FindFirstEx (const Path : String; Attr : TFileAttrs; out SearchRec : TSearchRecEx) : Longint;
{$IFDEF MSWINDOWS}
var
wPath: WideString;
wPath: UnicodeString;
begin
wPath:= UTF8Decode(Path);
wPath:= UTF16LongName(Path);
SearchRec.ExcludeAttr:= not Attr and faSpecial;
SearchRec.FindHandle:= FindFirstFileW(PWideChar(wPath), SearchRec.FindData);
// if error then exit