1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellApi;
type TForm1 = class(TForm) ListBox1: TListBox; Label1: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Button3: TButton; Button1: TButton; procedure ListBox1DblClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure ListBox1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject);
private public end;
var Form1: TForm1;
implementation
{$R *.dfm}
function RenameFileEx(const AOldName, ANewName: string; ARenameCheck: boolean = false): boolean; var sh: TSHFileOpStruct; begin sh.Wnd := Application.Handle; sh.wFunc := fo_Move;
sh.pFrom := PChar(AOldName + #0); sh.pTo := PChar(ANewName + #0); sh.fFlags := fof_Silent or fof_MultiDestFiles; if ARenameCheck then sh.fFlags := sh.fFlags or fof_RenameOnCollision; Result:=ShFileOperation(sh)=0; end;
procedure GetFilesInDirectory(Directory: string; const Mask: string; List: TStrings; WithSubDirs, ClearList: Boolean);
procedure ScanDir(const Directory: string); var SR: TSearchRec; begin if FindFirst(Directory + Mask, faAnyFile and not faDirectory, SR) = 0 then try repeat List.Add(Directory + SR.Name) until FindNext(SR) <> 0; finally FindClose(SR); end;
if WithSubDirs then begin if FindFirst(Directory + '*.*', faAnyFile, SR) = 0 then try repeat if ((SR.attr and faDirectory) = faDirectory) and (SR.Name <> '.') and (SR.Name <> '..') then ScanDir(Directory + SR.Name + '\'); until FindNext(SR) <> 0; finally FindClose(SR); end; end; end;
begin List.BeginUpdate; try if ClearList then List.Clear; if Directory = '' then Exit; if Directory[Length(Directory)] <> '\' then Directory := Directory + '\'; ScanDir(Directory); finally List.EndUpdate; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin RenameFileEx(Edit3.text, ??????????); end;
procedure TForm1.Button3Click(Sender: TObject); var s : string; i, i2 : integer; Source, Target : string; fullFileName : string;
begin fullFileName := Edit1.Text; Edit2.Text := ExtractFileName (fullFileName);
s:=Edit2.text; i:=Pos('-2010_',s); i2:=Pos('.mp4',s); Edit3.Text:=(IntToStr(i)+ ' / ' + IntToStr(i2));
i:=i-7; Source := Edit2.Text; Target := Copy(Source, 0, i); Edit3.Text:=(Target + ExtractFileExt (fullFileName)) ;
end;
procedure TForm1.FormCreate(Sender: TObject); begin GetFilesInDirectory('D:\test\', '*.*', Listbox1.Items, True, True); end;
procedure TForm1.ListBox1Click(Sender: TObject); begin Edit1.Text:=ListBox1.Items.Strings[ListBox1.ItemIndex]; end;
procedure TForm1.ListBox1DblClick(Sender: TObject); begin ShellExecute(Application.Handle, 'open', PChar(ListBox1.Items.Strings[ListBox1.ItemIndex]), Nil, Nil, SW_SHOW); end;
end. |