ST3VO
asked on
Rename All Files in a Folder
Hi all,
I've got some files in a folder under the following name format:
AFileName.jpg.off
I need to take out all the ".off" from all the files that have the ".off" at the end. from a folder.
Can someone please help?
Thanks again
ST3VO
I've got some files in a folder under the following name format:
AFileName.jpg.off
I need to take out all the ".off" from all the files that have the ".off" at the end. from a folder.
Can someone please help?
Thanks again
ST3VO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect ...Thanks :o)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure ScanDir(path: String;str:String);
var sr: TSearchRec;
NewName,s:String;
idx,len:Integer;
begin
if path[Length(path)] <> '\' then
path := path + '\';
if FindFirst(path + '*.*', faAnyFile, sr) = 0 then begin
repeat
len:= Length(sr.Name);
idx:=Pos(str, sr.Name);
if (idx <> 0) and ((len-idx)=3) then begin
NewName:=sr.Name;
Delete(NewName, idx, len-idx+1);
RenameFile(path+sr.Name, path+NewName);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
if FindFirst(path + '*.*', faAnyFile, sr) = 0 then begin
repeat
if (sr.Name <> '.') and (sr.name <> '..') then
if sr.Attr = faDirectory then
ScanDir(path + sr.Name + '\', str);
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
procedure TForm1.Button1Click(Sender
begin
ScanDir('C:\Test','.off');
ShowMessage('Done!');
end;
end.