unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TChOfSet = set of char;
TMain = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure GetFiles(APfad,AMaske:string);
public
{ Public-Deklarationen }
end;
var
Main: TMain;
implementation
uses
UnicodeFileUtils;
{$R *.dfm}
const
cUnicodeStr = ['?'];
function _StringToWideString(const S: AnsiString): WideString;
var
X : integer;
CodePage : word;
begin
CodePage := CP_ACP;
if S = ''
then Result := ''
else begin
X := MultiByteToWideChar(codePage, MB_PRECOMPOSED, PChar(@S[1]), - 1, nil, 0);
SetLength(result, X - 1);
if X > 1 then MultiByteToWideChar(CodePage, MB_PRECOMPOSED, PChar(@S[1]),- 1, PWideChar(@Result[1]), X - 1);
end;
end;
//------------------------------------------------------------------------------
function _UniCodeErkennen(var Value: string;Ch :TChOfSet):boolean;
var
I: integer;
begin
Result := false;
for I:=1 to length(Value) do
if Value[I] in Ch then
begin
Value[I] := '_';
Result := true;
end;
end;
//-----------------------------------------------------------------------------
procedure TMain.GetFiles(APfad,AMaske:string);
var
HFind : THandle;
Directory : string;
ToFile : string;
SRW : WIN32_FIND_DATAW;
begin
Directory:= ExtractFilePath(APfad);
try
HFind:=FindFirstFileW(PWideChar(_StringToWideString(APfad+AMaske)),SRW);
if HFind<>INVALID_HANDLE_VALUE then
begin
repeat
if SRW.dwFileAttributes and faDirectory <> faDirectory then
begin
ToFile := SRW.cFileName;
if _UniCodeErkennen(ToFile,cUnicodeStr) then
begin
ToFile :=APfad+ToFile;
if MoveFileA(PChar(APfad+SRW.cAlternateFileName),
PChar(ToFile)) then;
end;
begin
end;
end;
until FindNextFileW(HFind,SRW) <> true;
end;
except
end;
end;
//------------------------------------------------------------------------------
procedure TMain.Button1Click(Sender: TObject);
begin
GetFiles('C:\Temp\Test\1\','*.*');
end;
end.