2
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;

我正在使用 Inno setup 来创建自定义安装程序,我需要它来向我的安装程序添加一些东西。通过这段代码,我可以找到文件的最后修改日期,但我想在运行设置时将文件名作为输入。看这里

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

在此函数中,我将文件名作为参数传递。我想在运行设置时选择此文件名,就像选择目标文件夹向导一样,然后将选定的文件名作为参数传递给上述函数。

任何帮助,将不胜感激。提前致谢

4

2 回答 2

3

您正在寻找该GetOpenFileName函数,该函数显示一个对话框,使用户能够选择现有文件。以下脚本显示了当用户离开欢迎页面时如何显示此对话框。如果用户取消文件选择,他们将停留在欢迎页面:

[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;
于 2013-06-14T07:10:58.063 回答
0

总脚本,可能对你有帮助

#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;
于 2013-07-06T15:08:26.623 回答