PDA

View Full Version : تعویض تاریخ یک پوشه



darrudi
پنج شنبه 22 مهر 1389, 13:54 عصر
سلام دوستان
تابعی هست واسه اینکه تاریخ یک پوشه رو عوض کرد

mofrad
جمعه 23 مهر 1389, 00:27 صبح
سلام

program Project1;
{$APPTYPE CONSOLE}

uses
System.IO;

var
Path : String;

begin
// Create a new folder
Path := 'C:\Delphi testing';
System.IO.Directory.CreateDirectory(Path);

// Show the folder creation date and time
Console.WriteLine(System.IO.Directory.GetCreationT ime(Path));

// Change the creation date and time
System.IO.Directory.SetCreationTime(Path, DateTime.Create(2000, 1, 1));

// Show the folder creation date and time again
Console.WriteLine(System.IO.Directory.GetCreationT ime(Path));

// Delete this temporary folder
System.IO.Directory.Delete(Path);

Console.Readline;
end.

darrudi
جمعه 23 مهر 1389, 14:15 عصر
سلام

program Project1;
{$APPTYPE CONSOLE}

uses
System.IO;

var
Path : String;

begin
// Create a new folder
Path := 'C:\Delphi testing';
System.IO.Directory.CreateDirectory(Path);

// Show the folder creation date and time
Console.WriteLine(System.IO.Directory.GetCreationT ime(Path));

// Change the creation date and time
System.IO.Directory.SetCreationTime(Path, DateTime.Create(2000, 1, 1));

// Show the folder creation date and time again
Console.WriteLine(System.IO.Directory.GetCreationT ime(Path));

// Delete this temporary folder
System.IO.Directory.Delete(Path);

Console.Readline;
end.
با تشکر از پاسختون . اما من یک مشکل دارم با این System.io که میگه همچین Dcu تو ِDelphi شما نصب نیست میشه واسم بفرستین
ممنون میشم. من اغلب از این system .io تو #c استفاده میکردم

mofrad
جمعه 23 مهر 1389, 16:36 عصر
سلام.
کد بالا در دلفی دات نت کار میکنه.
کد زیر برای دلفی نسخه های غیر دات نتی!


function GetFolderDate(Folder: string): TDateTime;
var
Rec: TSearchRec;
Found: Integer;
Date: TDateTime;
begin
if Folder[Length(folder)] = '\' then
Delete(Folder, Length(folder), 1);
Result := 0;
Found := FindFirst(Folder, faDirectory, Rec);
try
if Found = 0 then
begin
Date := FileDateToDateTime(Rec.Time);
Result := Date;
end;
finally
FindClose(Rec);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
d: TDateTime;
begin
d := GetFolderDate('C:\MyFolder');
ShowMessage(FormatDateTime('dddd, d. mmmm yyyy, hh:mm:ss', d));
end;


{ Sets the time for both files and directories }
{ for NT }

function NT_SetDateTime(FileName: string; dtCreation, dtLastAccessTime, dtLastWriteTime: TDateTime): Boolean;
// by Nicholas Robinson
var
hDir: THandle;
ftCreation: TFiletime;
ftLastAccessTime: TFiletime;
ftLastWriteTime: TFiletime;

function DTtoFT(dt: TDateTime): TFiletime;
var
dwft: DWORD;
ft: TFiletime;
begin
dwft := DateTimeToFileDate(dt);
DosDateTimeToFileTime(LongRec(dwft).Hi, LongRec(dwft).Lo, ft);
LocalFileTimeToFileTime(ft, Result);
end;

begin
hDir := CreateFile(PChar(FileName),
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
0);
if hDir <> INVALID_HANDLE_VALUE then
begin
try
ftCreation := DTtoFT(dtCreation);
ftLastAccessTime := DTtoFT(dtLastAccessTime);
ftLastWriteTime := DTtoFT(dtLastWriteTime);
Result := SetFileTime(hDir, @ftCreation, @ftLastAccessTime, @ftLastWriteTime);
finally
CloseHandle(hDir);
end;
end
else
Result := False;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
NT_SetDateTime('c:\MyFolder', now, now, now);
end;