Domanda

const
    GetFileExInfoStandard = $0;

type 
    FILETIME = record 
      LowDateTime:  DWORD; 
      HighDateTime: DWORD; 
    end; 

    WIN32_FILE_ATTRIBUTE_DATA = record 
      FileAttributes: DWORD; 
      CreationTime:   FILETIME; 
      LastAccessTime: FILETIME; 
      LastWriteTime:  FILETIME; 
      FileSizeHigh:   DWORD; 
      FileSizeLow:    DWORD; 
    end; 

    SYSTEMTIME = record 
      Year:         WORD; 
      Month:        WORD; 
      DayOfWeek:    WORD; 
      Day:          WORD; 
      Hour:         WORD; 
      Minute:       WORD; 
      Second:       WORD; 
      Milliseconds: WORD; 
    end; 

function GetFileAttributesEx (
    FileName:            string;  
    InfoLevelId:         DWORD; 
    var FileInformation: WIN32_FILE_ATTRIBUTE_DATA
    ): Boolean; 
external 'GetFileAttributesExA@kernel32.dll stdcall'; 

function FileTimeToSystemTime(
    FileTime:        FILETIME; 
    var SystemTime:  SYSTEMTIME
    ): Boolean; 
external 'FileTimeToSystemTime@kernel32.dll stdcall'; 

procedure InitializeWizard();
    var 
      FileInformation: WIN32_FILE_ATTRIBUTE_DATA; 
      SystemInfo: SYSTEMTIME;     
begin
    GetFileAttributesEx('C:\Users\Gangadhar\Desktop\white_plain.gif', GetFileExInfoStandard , FileInformation); 

    FileTimeToSystemTime(FileInformation.LastWriteTime, SystemInfo); 

    MsgBox(format('%2.2d-%2.2d-%4.4d', [SystemInfo.Day, SystemInfo.Month, SystemInfo.Year]), mbInformation, MB_OK);
end;

I am using Inno setup to create custom installers, I need this to add some thing to my installer. By this code I can able to find the last modified date of the file , but I want to give the file name as input while running the setup. see here

GetFileAttributesEx('C:\Users\Gangadhar\Desktop\white_plain.gif', GetFileExInfoStandard , FileInformation);

in this function I was passed filename as a parameter.i want to select this filename while running the setup , as like select destination folder wizard and then pass that selected filename as parameter to the above function.

any help would be appreciated. Thanks in advance

È stato utile?

Soluzione

You're looking for the GetOpenFileName function, which displays a dialog box that enables the user to select an existing file. The following script shows how to display this dialog when user leaves the welcome page. If the user cancels the file selection, they will stay on the welcome page:

[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
  FileName: String;
begin
  // allow users to go through the wizard by default
  Result := True;
  // if the user is going to leave the welcome page, then... 
  if CurPageID = wpWelcome then
  begin
    // set the initial file name
    FileName := '';
    // open the file dialog; if the user cancels it, they will stay at
    // the welcome page (I don't know if it's your intention though)
    Result := GetOpenFileName('Select the file to check', FileName, '',
      'GIF Files (*.gif)|*.gif|All Files|*.*', '');
    // if the user selected a file, then do whatever you want with it
    if Result then
    begin
      // you got the file name in FileName variable
    end;
  end;  
end;

Altri suggerimenti

Total script, may helpful to you

#define MyAppName "showing the last modified date of selected file or directory"
#define MyAppVersion "1.5"
#define MyAppPublisher "My company"
#define MyAppURL "http://www.example.com/"
;#define MyAppExeName "MyProg.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{CD4CCA6A-5495-4132-98EE-44BC071E850B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
CreateAppDir=no
DisableDirPage=yes
DisableProgramGroupPage=yes
OutputDir=C:\Users\Gangadhar\Desktop\showing last modified date
OutputBaseFilename=last modified date of any file
Compression=lzma
SolidCompression=yes
DisableFinishedPage=yes

[Messages]
buttoninstall=&Close Application
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"


[Code]
const
    GetFileExInfoStandard = $0;


type 
    FILETIME = record 
      LowDateTime:  DWORD; 
      HighDateTime: DWORD; 
    end; 

    WIN32_FILE_ATTRIBUTE_DATA = record 
      FileAttributes: DWORD; 
      CreationTime:   FILETIME; 
      LastAccessTime: FILETIME; 
      LastWriteTime:  FILETIME; 
      FileSizeHigh:   DWORD; 
      FileSizeLow:    DWORD; 
    end; 

    SYSTEMTIME = record 
      Year:         WORD; 
      Month:        WORD; 
      DayOfWeek:    WORD; 
      Day:          WORD; 
      Hour:         WORD; 
      Minute:       WORD; 
      Second:       WORD; 
      Milliseconds: WORD; 
    end; 

 var
     FileInformation: WIN32_FILE_ATTRIBUTE_DATA;
       FileName: String;
       SystemInfo: SYSTEMTIME; 



function GetFileAttributesEx (
    FileName:            string;  
    InfoLevelId:         DWORD; 
    var FileInformation: WIN32_FILE_ATTRIBUTE_DATA
    ): Boolean; 
external 'GetFileAttributesExA@kernel32.dll stdcall';



function FileTimeToSystemTime(
    FileTime:        FILETIME; 
    var SystemTime:  SYSTEMTIME
    ): Boolean; 
external 'FileTimeToSystemTime@kernel32.dll stdcall'; 



function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo,
MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
  S: String;
  Months,days:tarrayofstring;
  i:integer;
begin
i:=0;
Months:=['January','February','March','April','May','June','July','August','September','October','November','December'];
Days:=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
S:='';       //Modified: 22 ?June ?2013, ??04:14:00 PM   ?24 ?June ?2013, ??02:38:18 PM
S:=S+Newline;
S:=S+'Selected Filename :'+Newline+Filename+Newline+Newline;
S:=S+'Last modified date of Selected file is:  ' ;
for i:=0 to 6 do 
begin
if SystemInfo.DayOfWeek=i then
S:=S+Days[i]+', ';
end;

S:=S+inttostr(SystemInfo.Day)+'-';
//January February March April May June July August September October November December 
for i:=0 to 11 do 
begin
if SystemInfo.Month=i+1 then
S:=S+Months[i];
end;

S:=S+'-'+inttostr(SystemInfo.Year);
Result:=S;
end;




 function NextButtonClick(CurPageID: Integer): Boolean;
begin
  // allow users to go through the wizard by default
  Result := True;
  // if the user is going to leave the welcome page, then... 
  if CurPageID = wpWelcome then
  begin
    // set the initial file name
    FileName := '';
    // open the file dialog; if the user cancels it, they will stay at
    // the welcome page (I don't know if it's your intention though)
    Result := GetOpenFileName('Select the file to check', FileName, '',
      'ALL Files (*.*)|*.*|All Files|*.*', '');
    // if the user selected a file, then do whatever you want with it
    if Result then
    begin
    GetFileAttributesEx(format('%s', [FileName]), GetFileExInfoStandard , FileInformation);
    FileTimeToSystemTime(FileInformation.LastWriteTime, SystemInfo); 

   // MsgBox(format('LAST MODIFIED DATE OF SELECTED FILE IS : %2.d-%2.2d-%4.4d', [SystemInfo.Day, SystemInfo.Month, SystemInfo.Year]), mbInformation, MB_OK);
      // you got the file name in FileName variable
    end;
  end;  
end;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top