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设置来创建自定义安装程序,我需要在安装程序中添加一些内容。 通过此代码,我可以找到文件的最后修改日期,但我想在运行安装程序时将文件名作为输入。 看到这里
GetFileAttributesEx('C:\ Users \ Gangadhar \ Desktop \ white_plain.gif',GetFileExInfoStandard,FileInformation);
在这个函数中,我将filename作为参数传递。我希望在运行安装程序时选择此文件名,就像选择目标文件夹向导一样,然后将选定的文件名作为参数传递给上面的函数。
任何帮助将不胜感激。 提前致谢
答案 0 :(得分: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;
答案 1 :(得分: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;