> > Er der nogen der kan komme med et eksempel på hvordan jeg kan rename
alle
> > filer i et bestemt dir til fx 'streng'+filnavnet.
> > Eller fx lave efternavnet om på alle filer.
>
> Et simpelt eksempel skrevet på ca. 12 min.:
>
> program Project2;
>
> {$APPTYPE CONSOLE}
>
> uses
> Classes,
> SysUtils;
>
> procedure FindFiles(Path : string; var FileList : TStringList);
> var
> SearchRec : TSearchRec;
> begin
> if Path[Length(Path)] <> '\' then
> Path := Path + '\';
> if FindFirst(Path + '*.*', faAnyFile, SearchRec) = 0 then
> while FindNext(SearchRec) = 0 do
> begin
> if SearchRec.Attr and faDirectory = faDirectory then
> begin
> if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
> FindFiles(Path + SearchRec.Name, FileList);
> end
> else
> FileList.Add(Path + SearchRec.Name);
> end;
> end;
>
> procedure RenameFiles(const FileList : TStringList; const PreString :
> string);
> var
> i : Integer;
> s : string;
> begin
> for i := 0 to FileList.Count - 1 do
> begin
> s := FileList.Strings[i];
> if not RenameFile(s, ExtractFilePath(s) + PreString + ExtractFileName(s))
then
> Writeln(FileList.Strings[i], ' was not renamed!');
> end;
> end;
>
> var
> FileList : TStringList;
>
> begin
> FileList := TStringList.Create;
> try
> FileList.Clear;
> FindFiles('C:\TEMP\DELPHI', FileList);
> RenameFiles(FileList, 'xxx');
> finally
> FileList.Free;
> end;
> end.
>
> Sorry for de tabs, men det er en gammel vane fra C/C++ :)
>
np, og tak