如保將一資料夾下的同一副檔全部變更為另一副檔名 |
尚未結案
|
lanbome
一般會員 發表:46 回覆:28 積分:14 註冊:2003-07-03 發送簡訊給我 |
|
likush
高階會員 發表:5 回覆:235 積分:103 註冊:2002-10-08 發送簡訊給我 |
Procedure TForm1.Button1Click(Sender: TObject);
Var
List: TStrings;
idx: integer;
Path, BackupName: String;
Procedure GetFileList(Const FileName: String; List: TStrings);
Var
H: THandle;
Data: TWIN32FindData;
Begin
H := FindFirstFile(PChar(FileName), Data);
If H <> INVALID_HANDLE_VALUE Then Begin
Try
List.Add(Data.cFileName);
While FindNextFile(H, Data) Do Begin
List.Add(Data.cFileName);
End;
Finally
windows.FindClose(H);
End;
End;
End;
Begin
List := TStringList.Create;
Try
GetFileList('C:\Test\*.Txt', List);
Path := ExtractFilePath('C:\test\*.txt');
For idx := 0 To List.Count - 1 Do
Begin
BackupName := Path List.Strings[idx];
BackupName := ChangeFileExt(BackupName, '.ASP');
If Not RenameFile(Path List.Strings[idx], BackupName) Then
Raise Exception.Create('Unable to create backup file.');
End;
Finally
FreeAndNil(List);
End;
End; 參考來源
http://delphi.ktop.com.tw/topic.php?topic_id=57379 =========================
讀萬卷書~不如來K.TOP走一遭
=========================
|
jimmy_wei
高階會員 發表:9 回覆:176 積分:147 註冊:2003-08-28 發送簡訊給我 |
提供你比較偷懶的方法...
放一個DirectoryListBox,和一個FileListBox元件
設好DirectoryListBox.FileListBox 為 FileListBox1
然後就很快樂了,寫個迴圈就好啦 var
i: Integer;
sNewFile, sPath: String;
begin
sPath:= DirectoryListBox1.Directory;
for i:=0 to FileListBox1.Items.Count-1 do
begin
sNewFile:= StringReplace(FileListBox1.Items.Strings[i], '.txt', '.asp', [rfIgnoreCase]);
RenameFile(sPath '\' FileListBox1.Items.Strings[i], sPath '\' sNewFile);
end;
|
lanbome
一般會員 發表:46 回覆:28 積分:14 註冊:2003-07-03 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |