首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在InnoSetup PreProcessor部分复制文件?

如何在InnoSetup PreProcessor部分复制文件?
EN

Stack Overflow用户
提问于 2013-01-29 11:52:54
回答 2查看 4.8K关注 0票数 5

我只想在编译开始之前将一个文件复制到指定的目录中。

背景:I需要创建一些压缩文件。其中一个要包含的文件需要复制到最终的zip位置。(我不能直接从原来的位置压缩它,因为它会将原始路径保存在zip文件中。

我发现,preProcessor的动作非常适合这一点。我试图使用windows复制命令,但它不起作用。是否可以在preCompiler部分中使用代码部分中的函数?多么?还是有完全不同的方法来达到我的目标?

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-30 08:37:34

虽然我已经建议为这类任务使用批处理文件,但我已经制作了一个示例脚本,它处理某个目录中的所有*.tzs脚本文件,并且每个脚本都试图检查文件是否已经创建(如果存在的话,则更具体)。当然,这只是假设*.tzs脚本的基本用法,如帮助文件中所示。下面是:

代码语言:javascript
复制
#define FindHandle
#define FindResult
#define ScriptFile
#define ScriptLine
#define ScriptHandle
#define ArchiveFile
; unique identifier for the target archive file name property member
#define ArchiveToken ".Archive="
; path to directory, where all the *.tzs script files will be processed
#define ScriptPath "d:\Development\__StackOverflow\14579484\"
; tool, which will be used for the *.tzs file processing mentioned above
#define ScriptTool "c:\Program Files (x86)\TUGZip\TzScript.exe"

; This procedure tries to extract the name of the archive, to be created from
; the line currently read from the just processed *.tzs script file. It first
; tries to search the ArchiveToken constant value in trimmed, space-less line
; of script. If it's found, and the script line contains also two quotes, the 
; file name is stored to the ArchiveFile variable, by which is later checked 
; the file existence after the script execution is done
#sub ParseScriptLine  
  #define SrcPos = Pos("""", ScriptLine)
  #define EndPos = RPos("""", ScriptLine)
  #define ParsedStr = Trim(StringChange(ScriptLine, " ", ""))

  #if (Pos(ArchiveToken, ParsedStr) != 0) && (SrcPos != 0) && (EndPos != 0) && (SrcPos != EndPos)
    #expr ArchiveFile = Copy(ScriptLine, SrcPos + 1, EndPos - SrcPos - 1)
    #expr ArchiveFile = StringChange(ArchiveFile, "\\", "\")
    #if ArchiveFile != ""
      #pragma message "ExecuteScriptFile: ArchiveFile=" + ArchiveFile
      #expr ExecuteScriptFile      
    #endif
  #endif        
#endsub

; This procedure opens the currently processed *.tzs script file and starts to 
; read it line by line to get the file name of the archive to be created
#sub ReadScriptFile
  #pragma message "ReadScriptFile: ScriptFile=" + ScriptPath + ScriptFile
  #for {ScriptHandle = FileOpen(ScriptPath + ScriptFile); \
    ScriptHandle && !FileEof(ScriptHandle); ScriptLine = FileRead(ScriptHandle)} \
    ParseScriptLine
  #if ScriptHandle
    #expr FileClose(ScriptHandle)
  #endif
#endsub

; This procedure is used for the script execution itself, here the TzScript.exe
; tool is called passing the name of the currently processed script file. After
; this tool is done, it's checked if the expected archive file has been created 
#sub ExecuteScriptFile
  #if Exec(ScriptTool, ScriptPath + ScriptFile) == 0
    #if FileExists(ArchiveFile) == 0
      #error The expected archive was not found. Compilation will abort now!
    #endif
  #else
    #error An error occured at script tool starting. Compilation will abort now!
  #endif
#endsub

; This is the file iteration "callback"
#sub ProcessFoundFile
  #expr ScriptFile = FindGetFileName(FindHandle)
  #expr ReadScriptFile
#endsub

; This procedure is used to find all the *.tzs script files in folder, specified
; by the ScriptPath constant path. All the *.tzs files found there are executed 
; by the command line tool specified by the ScriptTool constant 
#for {FindHandle = FindResult = FindFirst(ScriptPath + "*.tzs", 0); \
  FindResult; FindResult = FindNext(FindHandle)} \
  ProcessFoundFile
#if FindHandle
  #expr FindClose(FindHandle)
#endif

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output
票数 2
EN

Stack Overflow用户

发布于 2013-01-29 11:59:59

您可以使用ISPP CopyFile()函数来完成此操作。

代码语言:javascript
复制
#expr CopyFile("C:\SourceFolder\FileName.exe", "C:\TargetFolder\FileName.exe")

请注意,无法从ISPP中使用[Code]函数,但您可以使用本机ISPP函数和宏。使用Exec()命令调用copy也会失败,因为它是命令处理器(cmd.exe)的特性,而不是单独的应用程序。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14582277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档