From: Jon Erik Oterhals <jonoter@stud.ntnu.no>
Brian Fløe Sørensen wrote: In Windows 95, you can see when a file was last accessed by right-clicking the file and selecting properties. How can I get this information in Delphi/API???
procedure TForm1.Button1Click(Sender: TObject); var FileHandle : THandle; LocalFileTime : TFileTime; DosFileTime : DWORD; LastAccessedTime : TDateTime; FindData : TWin32FindData; begin FileHandle := FindFirstFile('AnyFile.FIL', FindData); if FileHandle <> INVALID_HANDLE_VALUE then begin Windows.FindClose(Handle); if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then begin FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime); FileTimeToDosDateTime(LocalFileTime, LongRec(DosFileTime).Hi,LongRec(DosFileTime).Lo); LastAccessedTime := FileDateToDateTime(DosFileTime); Label1.Caption := DateTimeToStr(LastAccessedTime); end; end; end;
From: "DynaSoft." <TimH@onaustralia.com.au>
Here try these procedures.
Function GetShortFileName(Const FileName : String) : String; var aTmp: array[0..255] of char; begin if GetShortPathName(PChar(FileName),aTmp,Sizeof(aTmp)-1)=0 then Result:= FileName else Result:=StrPas(aTmp); end; Function GetLongFileName(Const FileName : String) : String; var aInfo: TSHFileInfo; begin if SHGetFileInfo(PChar(FileName),0,aInfo,Sizeof(aInfo),SHGFI_DISPLAYNAME)<>0 then Result:= String(aInfo.szDisplayName) else Result:= FileName; end;
From: Christian Piene Gundersen <j.c.p.gundersen@jusstud.uio.no>
> We need to know how can we get the serial number of a HDD, working with > Delphi 2.0
Try this:
procedure TForm1.Button1Click(Sender: TObject); var SerialNum : pdword; a, b : dword; Buffer : array [0..255] of char; begin if GetVolumeInformation('c:\', Buffer, SizeOf(Buffer), SerialNum, a, b, nil, 0) then Label1.Caption := IntToStr(SerialNum^); end;
From: "Angus Johnson" <ajohnson@rpi.net.au>
function DiskInDrive(const Drive: char): Boolean; var DrvNum: byte; EMode: Word; begin result := false; DrvNum := ord(Drive); if DrvNum >= ord('a') then dec(DrvNum,$20); EMode := SetErrorMode(SEM_FAILCRITICALERRORS); try if DiskSize(DrvNum-$40) <> -1 then result := true else messagebeep(0); finally SetErrorMode(EMode); end; end;
From: "Chris Rankin" <RankinC@Logica.com>
Vincent Oostindie <vincent.oostindie@tip.nl> wrote > * How do I get the unique number from an audio CD in the CD-ROM drive?
const MCI_INFO_PRODUCT = $00000100; MCI_INFO_FILE = $00000200; MCI_INFO_MEDIA_UPC = $00000400; MCI_INFO_MEDIA_IDENTITY = $00000800; MCI_INFO_NAME = $00001000; MCI_INFO_COPYRIGHT = $00002000; { parameter block for MCI_INFO command message } type PMCI_Info_ParmsA = ^TMCI_Info_ParmsA; PMCI_Info_ParmsW = ^TMCI_Info_ParmsW; PMCI_Info_Parms = PMCI_Info_ParmsA; TMCI_Info_ParmsA = record dwCallback: DWORD; lpstrReturn: PAnsiChar; dwRetSize: DWORD; end; TMCI_Info_ParmsW = record dwCallback: DWORD; lpstrReturn: PWideChar; dwRetSize: DWORD; end; TMCI_Info_Parms = TMCI_Info_ParmsA;
These are the buffers you want: the identifier is returned as a string of decimal digits by the MCI_INFO_MEDIA_IDENTITY function. You should be able to cross-reference this with the online help (Win32 and TMediaPlayer component).
program del; uses ShellApi; //function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer; stdcall; Var T:TSHFileOpStruct; P:String; begin P:='C:\Windows\System\EL_CONTROL.CPL'; With T do Begin Wnd:=0; wFunc:=FO_DELETE; pFrom:=Pchar(P); fFlags:=FOF_ALLOWUNDO End; SHFileOperation(T); End.From: bstowers@pobox.com (Brad Stowers) There are some other quirks you should be aware of, too:
An example of how to do this would be:
var FileList: string; FOS: TShFileOpStruct; begin FileList := 'c:\delete.me'#0'c:\windows\temp.$$$'#0#0; { if you were using filenames in string variables: } FileList := Filename1 + #0 + Filename2 + #0#0; FOS.pFrom := PChar(FileList); // blah blah blah end;