一个文件夹内除了指定文件。其他都修改。
比如:
文件夹123 里面有 11 12 13 14 15 16
除了11以外。都修改成 121 131 141 151 161
条件是这个11随时都变。可以是任何一个。12 13 14 都可以。
[最优解释]
改文件名还是改文件内容?
[其他解释]
FindFirstFile,FindNextFile,FindClose,首先把目录下的文件找出来,放到TStringList/TStringDynArray中,然后逐个判断是否是11,如果不是就改名,Windows下用MoveFile就可以改名字了.
[其他解释]
uses Generics.Collections;
TDictionary,这个类,有可能是你需要的.
-
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
pathstr:PChar;
fddata:TWin32FindData;
hd:THANDLE;
br:Bool;
EC:DWORD=0;
procedure TForm1.Button1Click(Sender: TObject);
begin
pathstr:='c:\windows\system32\*.dll';
hd:=FindFirstFile(pathstr,fddata);
while ( (hd<>INVALID_HANDLE_VALUE) and (EC<>ERROR_NO_MORE_FILES) ) do
begin
if ( fddata.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY )then
//if ((string(fddata.cFileName)<>'.') and (string(fddata.cFileName)<>'..')) then begin strcat() ...end;
begin
//never used
br:=FindNextFile(hd,fddata);
EC:=GetLastError();
end
else
begin
Listbox1.Items.Add(string(fddata.cFileName));
br:=FindNextFile(hd,fddata);
EC:=GetLastError();
end;
end;
windows.FindClose(hd);
end;
end.