E.1 File Functions Header
E.1.1 Introduction
Include header:
!include "FileFunc.nsh"
Call functions:
Section Install
${GetFileExt} "C:\My Downloads\Index.html" $R0
; $R0="html"
SectionEnd
Section un.Install
${GetParent} "C:\My Downloads\Index.html" $R0
; $R0="C:\My Downloads"
SectionEnd
E.1.2 Locate
Find files, directories and empty directories with mask and size options.
Syntax:
${Locate} "[Path]" "[Options]" "Function"
"[Path]" ; Disk or Directory
;
"[Options]" ; /L=[FD|F|D|DE|FDE]
; /L=FD - Locate Files and Directories (default)
; /L=F - Locate Files only
; /L=D - Locate Directories only
; /L=DE - Locate Empty Directories only
; /L=FDE - Locate Files and Empty Directories
; /M=[mask]
; /M=*.* - Locate all (default)
; /M=*.doc - Locate Work.doc, 1.doc ...
; /M=Pho* - Locate PHOTOS, phone.txt ...
; /M=win???.exe - Locate winamp.exe, winver.exe ...
; /M=winamp.exe - Locate winamp.exe only
; /S=No:No[B|K|M|G]
; /S= - Don't locate file size (faster) (default)
; /S=0:0B - Locate only files of 0 Bytes exactly
; /S=5:9K - Locate only files of 5 to 9 Kilobytes
; /S=:10M - Locate only files of 10 Megabyte or less
; /S=1G - Locate only files of 1 Gigabyte or more
; /G=[1|0]
; /G=1 - Locate with subdirectories (default)
; /G=0 - Locate without subdirectories
; /B=[0|1]
; /B=0 - Banner isn't used (default)
; /B=1 - Banner is used. Callback when function
; start to search in new directory
"Function" ; Callback function when found
Function "Function"
; $R9 "path\name"
; $R8 "path"
; $R7 "name"
; $R6 "size" ($R6="" if directory, $R6="0" if file with /S=)
; $R0-$R5 are not used (save data in them).
; ...
Push $var ; If $var="StopLocate" Then exit from function
FunctionEnd
Note:
- Error flag if disk or directory isn't exist
- Error flag if syntax error
- See also Locate plugin
Example (Find one file):
Section
${Locate} "C:\ftp" "/L=F /M=RPC DCOM.rar /S=1K" "Example1"
; 'RPC DCOM.rar' file in 'C:\ftp' with size 1 Kb or more
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "$$R0=$R0"
SectionEnd
Function Example1
StrCpy $R0 $R9
; $R0="C:\ftp\files\RPC DCOM.rar"
MessageBox MB_YESNO '$R0$\n$\nFind next?' IDYES +2
StrCpy $0 StopLocate
Push $0
FunctionEnd
Example (Write results to a text file):
Section
GetTempFileName $R0
FileOpen $R1 $R0 w
${Locate} "C:\ftp" "/S=:2M /G=0" "Example2"
; folders and all files with size 2 Mb or less
; don't scan subdirectories
FileClose $R1
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec '"notepad.exe" "$R0"'
SectionEnd
Function Example2
StrCmp $R6 '' 0 +3
FileWrite $R1 "Directory=$R9$\r$\n"
goto +2
FileWrite $R1 "File=$R9 Size=$R6 Mb$\r$\n"
Push $0
FunctionEnd
Example (Write results to an INI file):
Section
GetTempFileName $R0
${Locate} "C:\ftp" "/L=F /S=0K" "Example3"
; all files in 'C:\ftp' with size detect in Kb
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec '"notepad.exe" "$R0"'
SectionEnd
Function Example3
WriteINIStr $R0 "$R8" "$R7" "$R6 Kb"
Push $0
FunctionEnd
Example (Delete empty directories):
Section
StrCpy $R2 0
StrCpy $R3 0
loop:
StrCpy $R1 0
${Locate} "C:\ftp" "/L=DE" "Example4"
IntOp $R3 $R3 + 1
IntOp $R2 $R2 + $R1
StrCmp $R0 StopLocate +2
StrCmp $R1 0 0 loop
IfErrors 0 +2
MessageBox MB_OK 'error' IDOK +2
MessageBox MB_OK '$R2 directories were removed$\n$R3 loops'
SectionEnd
Function Example4
MessageBox MB_YESNOCANCEL 'Delete empty "$R9"?' IDNO end IDCANCEL cancel
RMDir $R9
IntOp $R1 $R1 + 1
goto end
cancel:
StrCpy $R0 StopLocate
end:
Push $R0
FunctionEnd
Example (Move all files into one folder):
Section
StrCpy $R0 "C:\ftp" ;Directory move from
StrCpy $R1 "C:\ftp2" ;Directory move into
StrCpy $R2 0
StrCpy $R3 0
${Locate} "$R0" "/L=F" "Example5"
IfErrors 0 +2
MessageBox MB_OK 'error' IDOK +4
StrCmp $R3 0 0 +2
MessageBox MB_OK '$R2 files were moved' IDOK +2
MessageBox MB_OK '$R2 files were moved$\n$R3 files were NOT moved'
SectionEnd
Function Example5
StrCmp $R8 $R1 +6
IfFileExists '$R1\$R7' +4
Rename $R9 '$R1\$R7'
IntOp $R2 $R2 + 1
goto +2
IntOp $R3 $R3 + 1
Push $0
FunctionEnd
Example (Copy files with log):
Section
StrCpy $R0 "C:\ftp" ;Directory copy from
StrCpy $R1 "C:\ftp2" ;Directory copy into
StrLen $R2 $R0
GetTempFileName $0
FileOpen $R3 $0 w
${Locate} "$R0" "/L=FDE" "Example6"
FileClose $R3
IfErrors 0 +2
MessageBox MB_OK 'error'
Exec '"notepad.exe" "$0"' ;view log
SectionEnd
Function Example6
StrCpy $1 $R8 '' $R2
StrCmp $R6 '' 0 +3
CreateDirectory '$R1$1\$R7'
goto end
CreateDirectory '$R1$1'
CopyFiles /SILENT $R9 '$R1$1'
IfFileExists '$R1$1\$R7' 0 +3
FileWrite $R3 "-old:$R9 -new:$R1$1\$R7 -success$\r$\n"
goto +2
FileWrite $R3 "-old:$R9 -new:$R1$1\$R7 -failed$\r$\n"
end:
Push $0
FunctionEnd
Example (Recreate directory structure):
Section
StrCpy $R0 "C:\ftp" ;Directory structure from
StrCpy $R1 "C:\ftp2" ;Directory structure into
StrLen $R2 $R0
${Locate} "$R0" "/L=D" "Example7"
IfErrors 0 +2
MessageBox MB_OK 'error'
SectionEnd
Function Example7
StrCpy $1 $R9 '' $R2
CreateDirectory '$R1$1'
Push $0
FunctionEnd
Example (Locate with banner - NxS plugin required):
Section
nxs::Show /NOUNLOAD `$(^Name) Setup` /top `Setup searching something$\r$\nPlease wait... If you can..` /h 1 /can 1 /end
${Locate} "C:\WINDOWS" "/L=F /M=*.inf /B=1" "Example8"
nxs::Destroy
SectionEnd
Function Example8
StrCmp $R0 $R8 abortcheck
StrCpy $R0 $R8
nxs::Update /NOUNLOAD /sub "$R8" /pos 78 /end
abortcheck:
nxs::HasUserAborted /NOUNLOAD
Pop $0
StrCmp $0 1 0 +2
StrCpy $0 StopLocate
StrCmp $R9 '' end
;...
end:
Push $0
FunctionEnd
E.1.3 GetSize
Find the size of a file, files mask or directory.
Find the sum of the files, directories and subdirectories.
Syntax:
${GetSize} "[Path]" "[Options]" $var1 $var2 $var3
"[Path]" ; Disk or Directory
;
"[Options]" ; /M=[mask]
; /M=*.* - Find all (default)
; /M=*.doc - Find Work.doc, 1.doc ...
; /M=Pho* - Find PHOTOS, phone.txt ...
; /M=win???.exe - Find winamp.exe, winver.exe ...
; /M=winamp.exe - Find winamp.exe only
; /S=No:No[B|K|M|G]
; /S= - Don't find file size (faster) (default)
; /S=0:0B - Find only files of 0 Bytes exactly
; /S=5:9K - Find only files of 5 to 9 Kilobytes
; /S=:10M - Find only files of 10 Megabyte or less
; /S=1G - Find only files of 1 Gigabyte or more
; /G=[1|0]
; /G=1 - Find with subdirectories (default)
; /G=0 - Find without subdirectories
;
$var1 ; Result1: Size
$var2 ; Result2: Sum of files
$var3 ; Result3: Sum of directories
Note:
- Error flag if disk or directory isn't exist
- Error flag if syntax error
- See also Locate plugin
Example (1):
Section
; Find file size "C:\WINDOWS\Explorer.exe" in kilobytes
${GetSize} "C:\WINDOWS" "/M=Explorer.exe /S=0K /G=0" $0 $1 $2
; $0="220" Kb
; $1="1" files
; $2="" directories
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Example (2):
Section
; Find folder size "C:\Installs\Reanimator\Drivers" in megabytes
${GetSize} "C:\Installs\Reanimator\Drivers" "/S=0M" $0 $1 $2
; $0="132" Mb
; $1="555" files
; $2="55" directories
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Example (3):
Section
; Find sum of files and folders "C:\WINDOWS" (no subfolders)
${GetSize} "C:\WINDOWS" "/G=0" $0 $1 $2
; $0="" size
; $1="253" files
; $2="46" directories
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
E.1.4 DriveSpace
Get total, occupied or free space of the drive.
Syntax:
${DriveSpace} "[Drive]" "[Options]" $var
"[Drive]" ; Disk to check
;
"[Options]" ; /D=[T|O|F]
; /D=T - Total space (default)
; /D=O - Occupied space
; /D=F - Free space
; /S=[B|K|M|G]
; /S=B - size in Bytes (default)
; /S=K - size in Kilobytes
; /S=M - size in Megabytes
; /S=G - size in Gigabytes
;
$var ; Result: Size
Note:
- Error flag if disk isn't exist or not ready
- Error flag if syntax error
Example:
Section
${DriveSpace} "C:\" "/D=F /S=M" $R0
; $R0="2530" megabytes free on drive C:
SectionEnd
E.1.5 GetDrives
Find all available drives in the system.
Syntax:
${GetDrives} "[Option]" "Function"
"[Option]" ; [FDD+HDD+CDROM+NET+RAM]
; FDD Floppy Disk Drives
; HDD Hard Disk Drives
; CDROM CD-ROM Drives
; NET Network Drives
; RAM RAM Disk Drives
;
; [ALL]
; Find all drives by letter (default)
;
"Function" ; Callback function when found
Function "Function"
; $9 "drive letter" (a:\ c:\ ...)
; $8 "drive type" (FDD HDD ...)
; $R0-$R9 are not used (save data in them).
; ...
Push $var ; If $var="StopGetDrives" Then exit from function
FunctionEnd
Example1:
Section
${GetDrives} "FDD+CDROM" "Example1"
SectionEnd
Function Example1
MessageBox MB_OK "$9 ($8 Drive)"
Push $0
FunctionEnd
Example2:
Section
${GetDrives} "ALL" "Example2"
SectionEnd
Function Example2
MessageBox MB_OK "$9 ($8 Drive)"
Push $0
FunctionEnd
Example3 (Get type of drive):
Section
StrCpy $R0 "D:\" ;Drive letter
StrCpy $R1 "invalid"
${GetDrives} "ALL" "Example3"
MessageBox MB_OK "Type of drive $R0 is $R1"
SectionEnd
Function Example3
StrCmp $9 $R0 0 +3
StrCpy $R1 $8
StrCpy $0 StopGetDrives
Push $0
FunctionEnd
E.1.6 GetTime
Get local or system time.
Get file time (access, creation and modification).
Syntax:
${GetTime} "[File]" "[Option]" $var1 $var2 $var3 $var4 $var5 $var6 $var7
"[File]" ; Ignored if "L" or "LS"
;
"[Option]" ; [Options]
; L Local time
; A last Access file time
; C Creation file time
; M Modification file time
; LS System time (UTC)
; AS last Access file time (UTC)
; CS Creation file time (UTC)
; MS Modification file time (UTC)
;
$var1 ; Result1: day
$var2 ; Result2: month
$var3 ; Result3: year
$var4 ; Result4: day of week name
$var5 ; Result5: hour
$var6 ; Result6: minute
$var7 ; Result7: seconds
Note:
- Error flag if file isn't exist
- Error flag if syntax error
- See also Time plugin
Example (Get local time):
Section
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
; $0="01" day
; $1="04" month
; $2="2005" year
; $3="Friday" day of week name
; $4="16" hour
; $5="05" minute
; $6="50" seconds
MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6'
SectionEnd
Example (Get file time):
Section
${GetTime} "$WINDIR\Explorer.exe" "C" $0 $1 $2 $3 $4 $5 $6
; $0="12" day
; $1="10" month
; $2="2004" year
; $3="Tuesday" day of week name
; $4="2" hour
; $5="32" minute
; $6="03" seconds
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6'
SectionEnd
Example (Get system time):
Section
${GetTime} "" "LS" $0 $1 $2 $3 $4 $5 $6
; $0="01" day
; $1="04" month
; $2="2005" year
; $3="Friday" day of week name
; $4="11" hour
; $5="05" minute
; $6="50" seconds
MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6'
SectionEnd
Example (Convert time to 12-hour format AM/PM):
Section
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
StrCmp $4 0 0 +3
StrCpy $4 12
goto +3
StrCmp $4 12 +5
IntCmp $4 12 0 0 +3
StrCpy $7 AM
goto +3
IntOp $4 $4 - 12
StrCpy $7 PM
MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6 $7'
SectionEnd
E.1.7 GetFileAttributes
Get attributes of file or directory.
Syntax:
${GetFileAttributes} "[File]" "[Attributes]" $var
"[File]" ; File or directory
;
"[Attributes]" ; "ALL" (default)
; -all attributes of file combined with "|" to output
;
; "READONLY|HIDDEN|SYSTEM|DIRECTORY|ARCHIVE|
; DEVICE|NORMAL|TEMPORARY|SPARSE_FILE|REPARSE_POINT|
; COMPRESSED|OFFLINE|NOT_CONTENT_INDEXED|ENCRYPTED"
; -file must have specified attributes
;
$var ; Result:
; $var=attr1|attr2|... (if used "ALL")
; $var=1 file has specified attributes
; $var=0 file has no specified attributes
Note:
- Error flag if file doesn't exist
Example1:
Section
${GetFileAttributes} "C:\MSDOS.SYS" "ALL" $R0
; $R0=READONLY|HIDDEN|SYSTEM|ARCHIVE
SectionEnd
Example2:
Section
${GetFileAttributes} "C:\MSDOS.SYS" "SYSTEM|HIDDEN" $R0
; $R0=1
SectionEnd
Example3:
Section
${GetFileAttributes} "C:\MSDOS.SYS" "NORMAL" $R0
; $R0=0
SectionEnd
E.1.8 GetFileVersion
Get version information from executable file.
Syntax:
${GetFileVersion} "[Executable]" $var
"[Executable]" ; Executable file (*.exe *.dll ...)
$var ; Result: Version number
Note:
- Error flag if file doesn't exist
- Error flag if file doesn't contain version information
Example:
Section
${GetFileVersion} "C:\ftp\program.exe" $R0
; $R0="1.1.0.12"
SectionEnd
E.1.9 GetExeName
Get installer filename (with valid case for Windows 98/Me).
Syntax:
${GetExeName} $var
Example:
Section
${GetExeName} $R0
; $R0="C:\ftp\program.exe"
SectionEnd
E.1.10 GetExePath
Get installer pathname ($EXEDIR with valid case for Windows 98/Me).
Syntax:
${GetExePath} $var
Example:
Section
${GetExePath} $R0
; $R0="C:\ftp"
SectionEnd
E.1.11 GetParameters
Get command line parameters.
Syntax:
${GetParameters} $var
Example:
Section
${GetParameters} $R0
; $R0="[parameters]"
SectionEnd
E.1.12 GetOptions
Get options from command line parameters.
Syntax:
${GetOptions} "[Parameters]" "[Option]" $var
"[Parameters]" ; command line parameters
;
"[Option]" ; option name
;
$var ; Result: option string
Note:
- Error flag if option not found
- First option symbol it is delimiter
Example1:
Section
${GetOptions} "/S /T" "/T" $R0
IfErrors 0 +2
MessageBox MB_OK "Not found" IDOK +2
MessageBox MB_OK "Found"
SectionEnd
Example2:
Section
${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes" "-INSTDIR=" $R0
;$R0=C:\Program Files\Common Files
SectionEnd
Example3:
Section
${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/Common Files" /ADMIN=password' "/INSTDIR=" $R0
;$R0=C:/Program Files/Common Files
SectionEnd
Example4:
Section
${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/Common Files"' -ADMIN=password` "-INSTDIR=" $R0
;$R0="C:/Program Files/Common Files"
SectionEnd
E.1.13 GetOptionsS
Same as GetOptions, but case sensitive.
E.1.14 GetRoot
Get root directory.
Syntax:
${GetRoot} "[FullPath]" $var
Example1:
Section
${GetRoot} "C:\Program Files\NSIS" $R0
; $R0="C:"
SectionEnd
Example2:
Section
${GetRoot} "\\SuperPimp\NSIS\Source\exehead\Ui.c" $R0
; $R0="\\SuperPimp\NSIS"
SectionEnd
E.1.15 GetParent
Get parent directory.
Syntax:
${GetParent} "[PathString]" $var
Example:
Section
${GetParent} "C:\Program Files\Winamp\uninstwa.exe" $R0
; $R0="C:\Program Files\Winamp"
SectionEnd
E.1.16 GetFileName
Get last part from directory path.
Syntax:
${GetFileName} "[PathString]" $var
Example:
Section
${GetFileName} "C:\Program Files\Winamp\uninstwa.exe" $R0
; $R0="uninstwa.exe"
SectionEnd
E.1.17 GetBaseName
Get file name without extension.
Syntax:
${GetBaseName} "[FileString]" $var
Example:
Section
${GetBaseName} "C:\ftp\program.exe" $R0
; $R0="program"
SectionEnd
E.1.18 GetFileExt
Get extension of file.
Syntax:
${GetFileExt} "[FileString]" $var
Example:
Section
${GetFileExt} "C:\ftp\program.exe" $R0
; $R0="exe"
SectionEnd
E.1.19 BannerTrimPath
Trim string path for banner.
Syntax:
${BannerTrimPath} "[PathString]" "[Option]" $var
"[PathString]" ;
;
"[Option]" ; [Length][A|B|C|D]
;
; Length -Maximum string length
; A -Trim center path (default)
; (C:\root\...\third path)
; If A mode not possible Then will be used B mode
; B -Trim right path
; (C:\root\second path\...)
; If B mode not possible Then will be used C mode
; C -Trim right string
; (C:\root\second path\third p...)
; D -Trim right string + filename
; (C:\root\second p...\third path)
; If D mode not possible Then will be used C mode
;
$var ; Result: Trimmed path
Example:
Section
${BannerTrimPath} "C:\Server\Documents\Terminal\license.htm" "35A" $R0
;$R0=C:\Server\...\Terminal\license.htm
SectionEnd
Example (Banner plugin):
!include "WinMessages.nsh"
!include "FileFunc.nsh"
Section
Banner::show "Starting..."
Banner::getWindow
Pop $R1
${Locate} "$WINDIR" "/L=F /M=*.* /B=1" "LocateCallback"
Banner::destroy
SectionEnd
Function LocateCallback
StrCmp $R0 $R8 code
StrCpy $R0 $R8
${BannerTrimPath} "$R8" "38B" $R8
GetDlgItem $1 $R1 1030
SendMessage $1 ${WM_SETTEXT} 0 "STR:$R8"
code:
StrCmp $R9 '' end
;...
end:
Push $0
FunctionEnd
Example (NxS plugin):
!include "FileFunc.nsh"
Section
nxs::Show /NOUNLOAD `$(^Name) Setup`\
/top `Setup searching something$\nPlease wait$\nIf you can...`\
/h 1 /can 1 /end
${Locate} "$WINDIR" "/L=F /M=*.* /B=1" "LocateCallback"
nxs::Destroy
SectionEnd
Function LocateCallback
StrCmp $R0 $R8 abortcheck
StrCpy $R0 $R8
${BannerTrimPath} "$R8" "55A" $R8
nxs::Update /NOUNLOAD /sub "$R8" /pos 78 /end
abortcheck:
nxs::HasUserAborted /NOUNLOAD
Pop $0
StrCmp $0 1 0 +2
StrCpy $0 StopLocate
StrCmp $R9 '' end
;...
end:
Push $0
FunctionEnd
E.1.20 DirState
Check directory full, empty or not exist.
Syntax:
${DirState} "[path]" $var
"[path]" ; Directory
$var ; Result:
; $var=0 (empty)
; $var=1 (full)
; $var=-1 (directory not found)
Example:
Section
${DirState} "$TEMP" $R0
; $R0="1" directory is full
SectionEnd
E.1.21 RefreshShellIcons
After changing file associations, you can call this function to refresh the shell immediately.
Syntax:
${RefreshShellIcons}
Example:
Section
WriteRegStr HKCR "Winamp.File\DefaultIcon" "" "$PROGRAMFILES\Winamp\WINAMP.EXE,2"
${RefreshShellIcons}
SectionEnd
E.2 Text Functions Header
E.2.1 Introduction
Include header:
!include "TextFunc.nsh"
Call functions:
Section Install
${LineRead} "C:\a.log" "-1" $R0
; $R0="Last line$\r$\n"
SectionEnd
Section un.Install
${TrimNewLines} "Last line$\r$\n" $R0
; $R0="Last line"
SectionEnd
E.2.2 LineFind
Find specified lines in text file, and edit or view these lines in callback function.
Syntax:
${LineFind} "[File1]" "[File2|/NUL]" "[LineNumbers]" "Function"
"[File1]" ; Input text file
;
"[File2|/NUL]" ; [File2]
; Output text file
; If empty then File2=File1
; [/NUL]
; No output text file (only read File1)
;
"[LineNumbers]" ; [No|-No|No:No|{No}|{-No}|{No:No}]
; 1:-1 all lines to change (default)
; 2 second line from start
; -3 third line from end
; 5:9 range of lines from 5 to 9
; {2} only second line from start to output
; {-3} only third line from end to output
; {5:9} only range of lines from 5 to 9 to output
;
"Function" ; Callback function for specified lines
Function "Function"
; $R9 current line
; $R8 current line number
; $R7 current line negative number
; $R6 current range of lines
; $R5 handle of a file opened to read
; $R4 handle of a file opened to write ($R4="" if "/NUL")
; you can use any string functions
; $R0-$R3 are not used (save data in them).
; ...
Push $var ; If $var="StopLineFind" Then exit from function
; If $var="SkipWrite" Then skip current line (ignored if "/NUL")
FunctionEnd
Note:
- Error flag if input file doesn't exist
- Error flag if output file path doesn't exist
- Ranges must be specified on growth (2 4:5 9:-8 -5:-4 -2:-1)
- Output file will not be updated if no changes made.
Example1 (delete first two symbols):
Section
${LineFind} "C:\a.log" "C:\a-edited.log" "3:-1" "Example1"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function Example1
${TrimNewLines} '$R9' $R9
StrCpy $R9 $R9 '' 2
StrCpy $R9 '$R9$\r$\n'
;start from 3 line and delete first two symbols
Push $0
FunctionEnd
Example2 (show changed lines):
Section
${LineFind} "C:\a.log" "a.log" "{5:12 15 -6:-5 -1}" "Example2"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function Example2
${TrimNewLines} '$R9' $R9
StrCpy $R9 "$R9 ~Changed line ($R8)~$\r$\n"
Push $0
FunctionEnd
Example3 (delete lines):
Section
${LineFind} "C:\a.log" "\logs\a.log" "2:3 10:-5 -3:-2" "Example3"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function Example3
StrCpy $0 SkipWrite
Push $0
FunctionEnd
Example4 (insert lines):
Section
${LineFind} "C:\a.log" "" "10" "Example4
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function Example4
FileWrite $R4 "---First Line---$\r$\n"
FileWrite $R4 "---Second Line ...---$\r$\n"
Push $0
FunctionEnd
Example5 (replace in file with count of changes - "WordFunc.nsh" required):
!include "WordFunc.nsh"
Section
StrCpy $R0 0
${LineFind} "C:\a.log" "C:\logs\a.log" "1:-1" "Example5"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "Changed lines=$R0"
SectionEnd
Function Example5
StrCpy $1 $R9
${WordReplace} '$R9' ' ' '_' '+*' $R9
StrCmp $1 $R9 +2
IntOp $R0 $R0 + 1
;$R0 count of changed lines
Push $0
FunctionEnd
Example6 (line string to cut or delete):
Section
${LineFind} "\a.log" "C:\logs\a.log" "" "Example6"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "Processed lines=$R1:$R2"
SectionEnd
Function Example6
;(Cut lines from a line to another line (also including that line))
StrCmp $R0 finish stop
StrCmp $R0 start finish
StrCmp $R9 'Start Line$\r$\n' 0 skip
StrCpy $R0 start
StrCpy $R1 $R8
goto code
finish:
StrCmp $R9 'Finish Line$\r$\n' 0 code
StrCpy $R0 finish
StrCpy $R2 $R8
goto code
skip:
StrCpy $0 SkipWrite
goto output
stop:
StrCpy $0 StopLineFind
goto output
;;(Delete lines from a line to another line (also including that line))
; StrCmp $R0 finish code
; StrCmp $R0 start finish
; StrCmp $R9 'Start Line$\r$\n' 0 code
; StrCpy $R0 start
; StrCpy $R1 $R8
; goto skip
; finish:
; StrCmp $R9 'Finish Line$\r$\n' 0 skip
; StrCpy $R0 finish
; StrCpy $R2 $R8
; skip:
; StrCpy $0 SkipWrite
; goto output
code:
;...
output:
Push $0
FunctionEnd
Example7 (read lines):
Section
${LineFind} "C:\a.log" "/NUL" "1:-1" "Example7"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function Example7
MessageBox MB_OKCANCEL '$$R9 "Line"=[$R9]$\n$$R8 "#" =[$R8]' IDOK +2
StrCpy $0 StopLineFind
Push $0
FunctionEnd
E.2.3 LineRead
Get line in file specified with number.
Syntax:
${LineRead} "[File]" "[LineNumber]" $var
"[File]" ; Input text file
;
"[LineNumber]" ; [No|-No]
; 3 line number from start
; -5 line number from end
;
$var ; Result: Line
Note:
- Error flag if input file doesn't exist
- Error flag if line number not found
Example:
Section
${LineRead} "C:\a.log" "-1" $R0
; $R0="Last line$\r$\n"
SectionEnd
E.2.4 FileReadFromEnd
Read text file from end line by line.
Syntax:
${FileReadFromEnd} "[File]" "Function"
"[File]" ; Input text file
"Function" ; Callback function
Function "Function"
; $9 current line
; $8 current line number
; $7 current line negative number
; $R0-$R9 are not used (save data in them).
; ...
Push $var ; If $var="StopFileReadFromEnd" Then exit from function
FunctionEnd
Note:
- Error flag if input file doesn't exist
Example1:
Section
${FileReadFromEnd} "C:\a.log" "Example1"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function Example1
MessageBox MB_OKCANCEL '"Line"=[$9]$\n "#"=[$8]$\n "-#"=[$7]' IDOK +2
StrCpy $0 StopFileReadFromEnd
Push $0
FunctionEnd
Example2 (Reverse text file):
Section
GetTempFileName $R0
FileOpen $R1 $R0 w
${FileReadFromEnd} "C:\a.log" "Example2"
FileClose $R1
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec '"notepad.exe" "$R0"'
SectionEnd
Function Example2
StrCmp $7 -1 0 +5
StrCpy $1 $9 1 -1
StrCmp $1 '$\n' +3
StrCmp $1 '$\r' +2
StrCpy $9 '$9$\r$\n'
FileWrite $R1 "$9"
Push $0
FunctionEnd
E.2.5 LineSum
Get sum of lines in text file.
Syntax:
${LineSum} "[File]" $var
"[File]" ; Input file
$var ; Result: Sum of lines
Note:
- Error flag if input file doesn't exist
Example:
Section
${LineSum} "C:\a.log" $R0
; $R0="54"
SectionEnd
E.2.6 FileJoin
Join two files in one (File1 + File2 = File3).
Syntax:
${FileJoin} "[File1]" "[File2]" "[File3]"
"[File1]" ; Input File1
"[File2]" ; Input File2
"[File3]" ; Output File3
; If [File3]="" Then add [File2] to [File1]
Note:
- Error flag if input files don't exist
- Error flag if output file path doesn't exist
Example1 (Join: a.log + b.log = Z.log):
Section
${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\Z.log"
SectionEnd
Example2 (Add: a.log + b.log = a.log):
Section
${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\a.log"
SectionEnd
E.2.7 TextCompare
Compare two text files.
Syntax:
${TextCompare} "[File1]" "[File2]" "[Option]" "Function"
"[File1]" ; File1 Compare these lines
"[File2]" ; File2 Compare with these lines
"[Options]" ; (line-by-line):
; FastDiff Compare line N (File1) with line N (File2)
; Call function if Different lines found
; FastEqual Compare line N (File1) with line N (File2)
; Call function if Equal lines found
; (line number independent):
; SlowDiff Compare line N (File1) with all lines (File2)
; Call function if line N (File1) Different
; SlowEqual Compare line N (File1) with all lines (File2)
; Call function if line N (File1) Equal
"Function" ; Callback function
Function "Function"
; $9 "Line File1"
; $8 "Line number"
; $7 "Line File2" (empty if SlowDiff)
; $6 "Line number" (empty if SlowDiff)
; $R0-$R9 are not used (save data in them).
; ...
Push $var ; If $var="StopTextCompare" Then exit from function
FunctionEnd
Note:
- Error flag if File1 or File2 doesn't exist
- Error flag if syntax error
Example (Different or Equal):
Section
StrCpy $R0 ''
${TextCompare} "C:\1.txt" "C:\2.txt" "FastDiff" "Example1"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +4
StrCmp $R0 NotEqual 0 +2
MessageBox MB_OK "Files differ" IDOK +2
MessageBox MB_OK "Files identical"
SectionEnd
Function Example1
StrCpy $R0 NotEqual
StrCpy $0 StopTextCompare
Push $0
FunctionEnd
Example (Compare line-by-line - Different):
Section
StrCpy $R0 'Text1.txt'
StrCpy $R1 'Text2.txt'
GetTempFileName $R2
FileOpen $R3 $R2 w
FileWrite $R3 "$R0 | $R1$\r$\n"
${TextCompare} "$R0" "$R1" "FastDiff" "Example2"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec "notepad.exe $R2"
FunctionEnd
Function Example2
FileWrite $R3 '$8=$9'
FileWrite $R3 '$6=$7$\r$\n'
Push $0
FunctionEnd
Example (Compare line-by-line - Equal):
Section
StrCpy $R0 'Text1.txt'
StrCpy $R1 'Text2.txt'
GetTempFileName $R2
FileOpen $R3 $R2 w
FileWrite $R3 "$R0 | $R1$\r$\n"
${TextCompare} "$R0" "$R1" "FastEqual" "Example3"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec "notepad.exe $R2"
FunctionEnd
Function Example3
FileWrite $R3 '$8|$6=$9'
Push $0
FunctionEnd
Example (Compare all lines - Different):
Section
StrCpy $R0 'Text1.txt'
StrCpy $R1 'Text2.txt'
GetTempFileName $R2
FileOpen $R3 $R2 w
FileWrite $R3 "$R0 | $R1$\r$\n"
${TextCompare} "$R0" "$R1" "SlowDiff" "Example4"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK end
FileWrite $R3 "$\r$\n$R1 | $R0$\r$\n"
${TextCompare} "$R1" "$R0" "SlowDiff" "Example4"
FileClose $R3
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK end
Exec "notepad.exe $R2"
end:
FunctionEnd
Function Example4
FileWrite $R3 '$8=$9'
Push $0
FunctionEnd
Example (Compare all lines - Equal):
Section
StrCpy $R0 'Text1.txt'
StrCpy $R1 'Text2.txt'
GetTempFileName $R2
FileOpen $R3 $R2 w
FileWrite $R3 "$R0 | $R1$\r$\n"
${TextCompare} "$R0" "$R1" "SlowEqual" "Example5"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec "notepad.exe $R2"
FunctionEnd
Function Example5
FileWrite $R3 '$8|$6=$9'
Push $0
FunctionEnd
Example (Show variables):
Section
${TextCompare} "C:\1.txt" "C:\2.txt" "FastDiff" "Example6"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function Example6
MessageBox MB_OKCANCEL '$$9 "Line File1" =[$9]$\n$$8 "Line #" =[$8]$\n$$7 "Line File2" =[$7]$\n$$6 "Line #" =[$6]' IDOK +2
StrCpy $0 StopTextCompare
Push $0
FunctionEnd
E.2.8 TextCompareS
Same as TextCompare, but case sensitive.
E.2.9 ConfigRead
Read value from entry name in config file.
Syntax:
${ConfigRead} "[File]" "[Entry]" $var
"[File]" ; config file
;
"[Entry]" ; entry name
;
$var ; Result: Value
Note:
- Error flag if entry not found
- Error flag if file doesn't exist
Example1:
Section
${ConfigRead} "C:\AUTOEXEC.BAT" "SET winbootdir=" $R0
;$R0=C:\WINDOWS
SectionEnd
Example2:
Section
${ConfigRead} "C:\apache\conf\httpd.conf" "Timeout " $R0
;$R0=30
SectionEnd
E.2.10 ConfigReadS
Same as ConfigRead, but case sensitive.
E.2.11 ConfigWrite
Write value from entry name in config file.
Syntax:
${ConfigWrite} "[File]" "[Entry]" "[Value]" $var
"[File]" ; config file
;
"[Entry]" ; entry name
;
"[Value]" ; value name
; if "" then delete Entry
;
$var ; Result:
; $var=CHANGED Value is written
; $var=DELETED Entry is deleted
; $var=ADDED Entry and Value are added
; $var=SAME Entry and Value already exist
Note:
- Error flag if file doesn't exist
- Error flag if file can't be opened
Example1:
Section
${ConfigWrite} "C:\AUTOEXEC.BAT" "SET winbootdir=" "D:\WINDOWS" $R0
;$R0=CHANGED
SectionEnd
Example2:
Section
${ConfigWrite} "C:\apache\conf\httpd.conf" "Timeout " "30" $R0
;$R0=SAME
SectionEnd
Example3:
Section
${ConfigWrite} "C:\apache\conf\httpd.conf" "Timeout " "" $R0
;$R0=DELETED
SectionEnd
E.2.12 ConfigWriteS
Same as ConfigWrite, but case sensitive.
E.2.13 FileRecode
Recode text file from DOS to Windows format and vice-versa.
Syntax:
${FileRecode} "[File]" "[Format]"
"[File]" ;
;
"[Format]" ; OemToChar -from DOS to Windows
; CharToOem -from Windows to DOS
Note:
- Error flag if file doesn't exist
- Error flag if syntax error
Example:
Section
${FileRecode} "C:\SCANDISK.LOG" "CharToOem"
SectionEnd
E.2.14 TrimNewLines
Trim newlines in a string.
Syntax:
${TrimNewLines} "[string]" $var
"[string]" ; Input string
$var ; Result: String without '$\r' and '$\n' at the end
Example:
Section
${TrimNewLines} "Text line$\r$\n" $R0
; $R0="Text line"
SectionEnd
E.3 Word Functions Header
E.3.1 Introduction
Include header:
!include "WordFunc.nsh"
Call functions:
Section Install
${WordFind} "A--H---S" "-" "+2" $R0
; $R0="H"
SectionEnd
Section un.Install
${WordReplace} "A--H---S" "-" "x" "+3*" $R0
; $R0="A--HxS"
SectionEnd
E.3.2 WordFind
Multi-features string function.
Strings:
"[word+1][delimiter][word+2][delimiter][word+3]..."
"[delimiter][word+1][delimiter][word+2][delimiter]..."
"[delimiter][delimiter][word+1][delimiter][delimiter][delimiter]..."
"...[word-3][delimiter][word-2][delimiter][word-1]"
"...[delimiter][word-2][delimiter][word-1][delimiter]"
"...[delimiter][delimiter][word-1][delimiter][delimiter][delimiter]"
Syntax:
${WordFind} "[string]" "[delimiter]" "[E][options]" $var
"[string]" ;[string]
; input string
"[delimiter]" ;[delimiter]
; one or several symbols
"[E][options]" ;[options]
; +number : word number from start
; -number : word number from end
; +number} : delimiter number from start
; all space after this
; delimiter to output
; +number{ : delimiter number from start
; all space before this
; delimiter to output
; +number}} : word number from start
; all space after this word
; to output
; +number{{ : word number from start
; all space before this word
; to output
; +number{} : word number from start
; all space before and after
; this word (word exclude)
; +number*} : word number from start
; all space after this
; word to output with word
; +number{* : word number from start
; all space before this
; word to output with word
; # : sum of words to output
; * : sum of delimiters to output
; /word : number of word to output
;
;[E]
; with errorlevel output
; IfErrors:
; $var=1 delimiter not found
; $var=2 no such word number
; $var=3 syntax error (Use: +1,-1},#,*,/word,...)
;[]
; no errorlevel output (default)
; If some errors found then (result=input string)
;
$var ;output (result)
Note:
- Accepted numbers 1,01,001,...
Example (Find word by number):
Section
${WordFind} "C:\io.sys C:\Program Files C:\WINDOWS" " C:\" "-02" $R0
; $R0="Program Files"
SectionEnd
Example (Delimiter exclude):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "-2}" $R0
; $R0=" C:\logo.sys C:\WINDOWS"
SectionEnd
Example (Sum of words):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " C:\" "#" $R0
; $R0="3"
SectionEnd
Example (Sum of delimiters):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "*" $R0
; $R0="2"
SectionEnd
Example (Find word number):
Section
${WordFind} "C:\io.sys C:\Program Files C:\WINDOWS" " " "/Files" $R0
; $R0="3"
SectionEnd
Example ( }} ):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2}}" $R0
; $R0=" C:\WINDOWS"
SectionEnd
Example ( {} ):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2{}" $R0
; $R0="C:\io.sys C:\WINDOWS"
SectionEnd
Example ( *} ):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2*}" $R0
; $R0="C:\logo.sys C:\WINDOWS"
SectionEnd
Example (Get parent directory):
Section
StrCpy $R0 "C:\Program Files\NSIS\NSIS.chm"
; "C:\Program Files\NSIS\Include\"
; "C:\\Program Files\\NSIS\\NSIS.chm"
${WordFind} "$R0" "\" "-2{*" $R0
; $R0="C:\Program Files\NSIS"
; "C:\\Program Files\\NSIS"
SectionEnd
Example (Coordinates):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" ":\lo" "E+1{" $R0
; $R0="C:\io.sys C"
IfErrors end
StrLen $0 $R0 ; $0 = Start position of word (11)
StrLen $1 ':\lo' ; $1 = Word length (4)
; StrCpy $R0 $R1 $1 $0 ; $R0 = :\lo
end:
SectionEnd
Example (With errorlevel output):
Section
${WordFind} "[string]" "[delimiter]" "E[options]" $R0
IfErrors 0 end
StrCmp $R0 1 0 +2 ; errorlevel 1?
MessageBox MB_OK 'delimiter not found' IDOK end
StrCmp $R0 2 0 +2 ; errorlevel 2?
MessageBox MB_OK 'no such word number' IDOK end
StrCmp $R0 3 0 +2 ; errorlevel 3?
MessageBox MB_OK 'syntax error'
end:
SectionEnd
Example (Without errorlevel output):
Section
${WordFind} "C:\io.sys C:\logo.sys" "_" "+1" $R0
; $R0="C:\io.sys C:\logo.sys" (error: delimiter "_" not found)
SectionEnd
Example (If found):
Section
${WordFind} "C:\io.sys C:\logo.sys" ":\lo" "E+1{" $R0
IfErrors notfound found
found:
MessageBox MB_OK 'Found' IDOK end
notfound:
MessageBox MB_OK 'Not found'
end:
SectionEnd
Example (If found 2):
Section
${WordFind} "C:\io.sys C:\logo.sys" ":\lo" "+1{" $R0
StrCmp $R0 "C:\io.sys C:\logo.sys" notfound found ; error?
found:
MessageBox MB_OK 'Found' IDOK end
notfound:
MessageBox MB_OK 'Not found'
end:
SectionEnd
Example (To accept one word in string if delimiter not found):
Section
StrCpy $0 'OneWord'
StrCpy $1 1
loop:
${WordFind} "$0" " " "E+$1" $R0
IfErrors 0 code
StrCmp $1$R0 11 0 error
StrCpy $R0 $0
goto end
code:
; ...
IntOp $1 $1 + 1
goto loop
error:
StrCpy $1 ''
StrCpy $R0 ''
end:
; $R0="OneWord"
SectionEnd
E.3.3 WordFindS
Same as WordFind, but case sensitive.
E.3.4 WordFind2X
Find word between two delimiters.
Strings:
"[delimiter1][word+1][delimiter2][delimiter1][word+2][delimiter2]..."
"[text][delimiter1][text][delimiter1][word+1][delimiter2][text]..."
"...[delimiter1][word-2][delimiter2][delimiter1][word-1][delimiter2]"
"...[text][delimiter1][text][delimiter1][word-1][delimiter2][text]"
Syntax:
${WordFind2X} "[string]" "[delimiter1]" "[delimiter2]" "[E][options]" $var
"[string]" ;[string]
; input string
"[delimiter1]" ;[delimiter1]
; first delimiter
"[delimiter2]" ;[delimiter2]
; second delimiter
"[E][options]" ;[options]
; +number : word number from start
; -number : word number from end
; +number}} : word number from start all space
; after this word to output
; +number{{ : word number from end all space
; before this word to output
; +number{} : word number from start
; all space before and after
; this word (word exclude)
; +number*} : word number from start
; all space after this
; word to output with word
; +number{* : word number from start
; all space before this
; word to output with word
; # : sum of words to output
; /word : number of word to output
;
;[E]
; with errorlevel output
; IfErrors:
; $var=1 no words found
; $var=2 no such word number
; $var=3 syntax error (Use: +1,-1,#)
;[]
; no errorlevel output (default)
; If some errors found then (result=input string)
;
$var ;output (result)
Example (1):
Section
${WordFind2X} "[C:\io.sys];[C:\logo.sys];[C:\WINDOWS]" "[C:\" "];" "+2" $R0
; $R0="logo.sys"
SectionEnd
Example (2):
Section
${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1" $R0
; $R0="logo"
SectionEnd
Example (3):
Section
${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{{" $R0
; $R0="C:\WINDOWS C:\io.sys C:"
SectionEnd
Example (4):
Section
${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{}" $R0
; $R0="C:\WINDOWS C:\io.sys C:sys"
SectionEnd
Example (5):
Section
${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{*" $R0
; $R0="C:\WINDOWS C:\io.sys C:\logo."
SectionEnd
Example (6):
Section
${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "/logo" $R0
; $R0="2"
SectionEnd
Example (With errorlevel output):
Section
${WordFind2X} "[io.sys];[C:\logo.sys]" "\" "];" "E+1" $R0
; $R0="1" ("\...];" not found)
IfErrors 0 noerrors
MessageBox MB_OK 'Errorlevel=$R0' IDOK end
noerrors:
MessageBox MB_OK 'No errors'
end:
SectionEnd
E.3.5 WordFind2XS
Same as WordFind2X, but case sensitive.
E.3.6 WordFind3X
Find a word that contains a string, between two delimiters.
Syntax:
${WordFind3X} "[string]" "[delimiter1]" "[center]" "[delimiter2]" "[E][options]" $var
"[string]" ;[string]
; input string
"[delimiter1]" ;[delimiter1]
; first delimiter
"[center]" ;[center]
; center string
"[delimiter2]" ;[delimiter2]
; second delimiter
"[E][options]" ;[options]
; +number : word number from start
; -number : word number from end
; +number}} : word number from start all space
; after this word to output
; +number{{ : word number from end all space
; before this word to output
; +number{} : word number from start
; all space before and after
; this word (word exclude)
; +number*} : word number from start
; all space after this
; word to output with word
; +number{* : word number from start
; all space before this
; word to output with word
; # : sum of words to output
; /word : number of word to output
;
;[E]
; with errorlevel output
; IfErrors:
; $var=1 no words found
; $var=2 no such word number
; $var=3 syntax error (Use: +1,-1,#)
;[]
; no errorlevel output (default)
; If some errors found then (result=input string)
;
$var ;output (result)
Example (1):
Section
${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "+1" $R0
; $R0="1.AAB"
SectionEnd
Example (2):
Section
${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1" $R0
; $R0="2.BAA"
SectionEnd
Example (3):
Section
${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{{" $R0
; $R0="[1.AAB];"
SectionEnd
Example (4):
Section
${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{}" $R0
; $R0="[1.AAB];[3.BBB];"
SectionEnd
Example (5):
Section
${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{*" $R0
; $R0="[1.AAB];[2.BAA];"
SectionEnd
Example (6):
Section
${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "/2.BAA" $R0
; $R0="2"
SectionEnd
Example (With errorlevel output):
Section
${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "XX" "];" "E+1" $R0
; $R0="1" ("[...XX...];" not found)
IfErrors 0 noerrors
MessageBox MB_OK 'Errorlevel=$R0' IDOK end
noerrors:
MessageBox MB_OK 'No errors'
end:
SectionEnd
E.3.7 WordFind3XS
Same as WordFind3X, but case sensitive.
E.3.8 WordReplace
Replace or delete word from string.
Syntax:
${WordReplace} "[string]" "[word1]" "[word2]" "[E][options]" $var
"[string]" ;[string]
; input string
"[word1]" ;[word1]
; word to replace or delete
"[word2]" ;[word2]
; replace with (if empty delete)
"[E][options]" ;[options]
; +number : word number from start
; -number : word number from end
; +number* : word number from start multiple-replace
; -number* : word number from end multiple-replace
; + : replace all results
; +* : multiple-replace all results
; { : if exists replace all delimiters
; from left edge
; } : if exists replace all delimiters
; from right edge
; {} : if exists replace all delimiters
; from edges
; {* : if exists multiple-replace all
; delimiters from left edge
; }* : if exists multiple-replace all
; delimiters from right edge
; {}* : if exists multiple-replace all
; delimiters from edges
;
;[E]
; with errorlevel output
; IfErrors:
; $var=1 word to replace not found
; $var=2 no such word number
; $var=3 syntax error (Use: +1,-1,+1*,-1*,+,+*,{},{}*)
;[]
; no errorlevel output (default)
; If some errors found then (result=input string)
;
$var ;output (result)
Example (replace):
Section
${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" "SYS" "bmp" "+2" $R0
; $R0="C:\io.sys C:\logo.bmp C:\WINDOWS"
SectionEnd
Example (delete):
Section
${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" "SYS" "" "+" $R0
; $R0="C:\io. C:\logo. C:\WINDOWS"
SectionEnd
Example (multiple-replace 1):
Section
${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" " " " " "+1*" $R0
; +1* or +2* or +3* or +4* or +5* or +6*
; $R0="C:\io.sys C:\logo.sys C:\WINDOWS"
SectionEnd
Example (multiple-replace 2):
Section
${WordReplace} "C:\io.sys C:\logo.sysSYSsys C:\WINDOWS" "sys" "bmp" "+*" $R0
; $R0="C:\io.bmp C:\logo.bmp C:\WINDOWS"
SectionEnd
Example (multiple-replace 3):
Section
${WordReplace} "sysSYSsysC:\io.sys C:\logo.sys C:\WINDOWSsysSYSsys" "sys" "|" "{}*" $R0
; $R0="|C:\io.sys C:\logo.sys C:\WINDOWS|"
SectionEnd
Example (With errorlevel output):
Section
${WordReplace} "C:\io.sys C:\logo.sys" "sys" "bmp" "E+3" $R0
; $R0="2" (no such word number "+3")
IfErrors 0 noerrors
MessageBox MB_OK 'Errorlevel=$R0' IDOK end
noerrors:
MessageBox MB_OK 'No errors'
end:
SectionEnd
E.3.9 WordReplaceS
Same as WordReplace, but case sensitive.
E.3.10 WordAdd
Add words to string1 from string2 if not exist or delete words if exist.
Syntax:
${WordAdd} "[string1]" "[delimiter]" "[E][options]" $var
"[string1]" ;[string1]
; string for addition or removing
"[delimiter]" ;[delimiter]
; one or several symbols
"[E][options]" ;[options]
; +string2 : words to add
; -string2 : words to delete
;
;[E]
; with errorlevel output
; IfErrors:
; $var=1 delimiter is empty
; $var=3 syntax error (use: +text,-text)
;[]
; no errorlevel output (default)
; If some errors found then (result=input string)
;
$var ;output (result)
Example (add):
Section
${WordAdd} "C:\io.sys C:\WINDOWS" " " "+C:\WINDOWS C:\config.sys" $R0
; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
SectionEnd
Example (delete):
Section
${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
; $R0="C:\logo.sys"
SectionEnd
Example (add to one):
Section
${WordAdd} "C:\io.sys" " " "+C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
SectionEnd
Example (delete one):
Section
${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS" $R0
; $R0="C:\io.sys C:\logo.sys"
SectionEnd
Example (No new words found):
Section
${WordAdd} "C:\io.sys C:\logo.sys" " " "+C:\logo.sys" $R0
StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2
MessageBox MB_OK "No new words found to add"
SectionEnd
Example (No words deleted):
Section
${WordAdd} "C:\io.sys C:\logo.sys" " " "-C:\config.sys" $R0
StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2
MessageBox MB_OK "No words found to delete"
SectionEnd
Example (With errorlevel output):
Section
${WordAdd} "C:\io.sys C:\logo.sys" "" "E-C:\logo.sys" $R0
; $R0="1" (delimiter is empty "")
IfErrors 0 noerrors
MessageBox MB_OK 'Errorlevel=$R0' IDOK end
noerrors:
MessageBox MB_OK 'No errors'
end:
SectionEnd
E.3.11 WordAddS
Same as WordAdd, but case sensitive.
E.3.12 WordInsert
Insert word in string.
Syntax:
${WordInsert} "[string]" "[delimiter]" "[word]" "[E][options]" $var
"[string]" ;[string]
; input string
"[delimiter]" ;[delimiter]
; one or several symbols
"[word]" ;[word]
; word to insert
"[E][options]" ;[options]
; +number : word number from start
; -number : word number from end
;
;[E]
; with errorlevel output
; IfErrors:
; $var=1 delimiter is empty
; $var=2 wrong word number
; $var=3 syntax error (Use: +1,-1)
;[]
; no errorlevel output (default)
; If some errors found then (result=input string)
;
$var ;output (result)
Example (1):
Section
${WordInsert} "C:\io.sys C:\WINDOWS" " " "C:\logo.sys" "-2" $R0
; $R0="C:\io.sys C:\logo.sys C:\WINDOWS"
SectionEnd
Example (2):
Section
${WordInsert} "C:\io.sys" " " "C:\WINDOWS" "+2" $R0
; $R0="C:\io.sys C:\WINDOWS"
SectionEnd
Example (3):
Section
${WordInsert} "" " " "C:\WINDOWS" "+1" $R0
; $R0="C:\WINDOWS "
SectionEnd
Example (With errorlevel output):
Section
${WordInsert} "C:\io.sys C:\logo.sys" " " "C:\logo.sys" "E+4" $R0
; $R0="2" (wrong word number "+4")
IfErrors 0 noerrors
MessageBox MB_OK 'Errorlevel=$R0' IDOK end
noerrors:
MessageBox MB_OK 'No errors'
end:
SectionEnd
E.3.13 WordInsertS
Same as WordInsert, but case sensitive.
E.3.14 StrFilter
Convert string to uppercase or lowercase.
Set symbol filter.
Syntax:
${StrFilter} "[string]" "[options]" "[symbols1]" "[symbols2]" $var
"[string]" ;[string]
; input string
;
"[options]" ;[+|-][1|2|3|12|23|31][eng|rus]
; + : convert string to uppercase
; - : convert string to lowercase
; 1 : only Digits
; 2 : only Letters
; 3 : only Special
; 12 : only Digits + Letters
; 23 : only Letters + Special
; 31 : only Special + Digits
; eng : English symbols (default)
; rus : Russian symbols
;
"[symbols1]" ;[symbols1]
; symbols include (not changeable)
;
"[symbols2]" ;[symbols2]
; symbols exclude
;
$var ;output (result)
Note:
- Error flag if syntax error
- Same symbol to include & to exclude = to exclude
Example (UpperCase):
Section
${StrFilter} "123abc 456DEF 7890|%#" "+" "" "" $R0
; $R0="123ABC 456DEF 7890|%#"
SectionEnd
Example (LowerCase):
Section
${StrFilter} "123abc 456DEF 7890|%#" "-" "ef" "" $R0
; $R0="123abc 456dEF 7890|%#"
SectionEnd
Example (Filter1):
Section
${StrFilter} "123abc 456DEF 7890|%#" "2" "|%" "" $R0
; $R0="abcDEF|%" ;only Letters + |%
SectionEnd
Example (Filter2):
Section
${StrFilter} "123abc 456DEF 7890|%#" "13" "af" "4590" $R0
; $R0="123a 6F 78|%#" ;only Digits + Special + af - 4590
SectionEnd
Example (Filter3):
Section
${StrFilter} "123abc 456DEF 7890|%#" "+12" "b" "def" $R0
; $R0="123AbC4567890" ;only Digits + Letters + b - def
SectionEnd
Example (Filter4):
Section
${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "+12rus" "ä" "ãå" $R0
; $R0="123ÀÁÂ456ä7890" ;only Digits + Letters + ä - ãå
SectionEnd
Example (English + Russian Letters):
Section
${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "2rus" "" "" $R0
; $R0="ÀÁÂãäå" ;only Russian Letters
${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "2" "$R0" "" $R0
; $R0="abcÀÁÂDEFãäå" ;only English + Russian Letters
SectionEnd
Example (Word Capitalize):
Section
Push "_01-PERPETUOUS_DREAMER__-__THE_SOUND_OF_GOODBYE_(ORIG._MIX).MP3_"
Call Capitalize
Pop $R0
; $R0="_01-Perpetuous_Dreamer__-__The_Sound_Of_Goodbye_(Orig._Mix).mp3_"
${WordReplace} "$R0" "_" " " "+*" $R0
; $R0=" 01-Perpetuous Dreamer - The Sound Of Goodbye (Orig. Mix).mp3 "
${WordReplace} "$R0" " " "" "{}" $R0
; $R0="01-Perpetuous Dreamer - The Sound Of Goodbye (Orig. Mix).mp3"
SectionEnd
Function Capitalize
Exch $R0
Push $0
Push $1
Push $2
${StrFilter} '$R0' '-eng' '' '' $R0
${StrFilter} '$R0' '-rus' '' '' $R0
StrCpy $0 0
loop:
IntOp $0 $0 + 1
StrCpy $1 $R0 1 $0
StrCmp $1 '' end
StrCmp $1 ' ' +5
StrCmp $1 '_' +4
StrCmp $1 '-' +3
StrCmp $1 '(' +2
StrCmp $1 '[' 0 loop
IntOp $0 $0 + 1
StrCpy $1 $R0 1 $0
StrCmp $1 '' end
${StrFilter} '$1' '+eng' '' '' $1
${StrFilter} '$1' '+rus' '' '' $1
StrCpy $2 $R0 $0
IntOp $0 $0 + 1
StrCpy $R0 $R0 '' $0
IntOp $0 $0 - 2
StrCpy $R0 '$2$1$R0'
goto loop
end:
Pop $2
Pop $1
Pop $0
Exch $R0
FunctionEnd
E.3.15 StrFilterS
Same as StrFilter, but case sensitive.
E.3.16 VersionCompare
Compare version numbers.
Syntax:
${VersionCompare} "[Version1]" "[Version2]" $var
"[Version1]" ; First version
"[Version2]" ; Second version
$var ; Result:
; $var=0 Versions are equal
; $var=1 Version1 is newer
; $var=2 Version2 is newer
Example:
Section
${VersionCompare} "1.1.1.9" "1.1.1.01" $R0
; $R0="1"
SectionEnd
E.3.17 VersionConvert
Convert version in the numerical format which can be compared.
Syntax:
${VersionConvert} "[Version]" "[CharList]" $var
"[Version]" ; Version
;
"[CharList]" ; List of characters, which will be replaced by numbers
; "abcdefghijklmnopqrstuvwxyz" (default)
;
$var ; Result: converted version
Note:
- Converted letters are separated with dot
- If character is non-digit and not in list then it will be converted to dot
Example1:
Section
${VersionConvert} "9.0a" "" $R0
; $R0="9.0.01"
${VersionConvert} "9.0c" "" $R1
; $R1="9.0.03"
${VersionCompare} "$R0" "$R1" $R2
; $R2="2" version2 is newer
SectionEnd
Example2:
Section
${VersionConvert} "0.15c-9m" "" $R0
; $R0="0.15.03.9.13"
${VersionConvert} "0.15c-1n" "" $R1
; $R1="0.15.03.1.14"
${VersionCompare} "$R0" "$R1" $R2
; $R2="1" version1 is newer
SectionEnd
Example3:
Section
${VersionConvert} "0.15c+" "abcdefghijklmnopqrstuvwxyz+" $R0
; $R0="0.15.0327"
${VersionConvert} "0.15c" "abcdefghijklmnopqrstuvwxyz+" $R1
; $R1="0.15.03"
${VersionCompare} "$R0" "$R1" $R2
; $R2="1" version1 is newer
SectionEnd
文章出处:http://www.zhetao.com/content124
相关推荐
Include 编译需要的头文件,请自己复制Include下所有文件到NSIS目录下的Include如:C:\Program Files\NSIS\Include Plugins 编译需要的DLL插件,请自己复制Plugins下所有文件到NSIS目录下的Plugins如:C:\Program ...
当在NSIS脚本中使用TCP.dll时,需要包含此头文件来正确地调用DLL中的函数。 在NSIS脚本中,开发者可以使用以下步骤来检测端口是否被占用: 1. 引入TCP.dll:在NSIS脚本中,首先需要声明引入TCP.dll,这通常通过`!...
通过本文的介绍,我们了解了NSIS脚本语法的基本组成部分,包括注释、数据类型、续行符、默认头文件、标号、相对跳转等基础概念,同时也探讨了更高级的主题如头文件、安装属性、页面及其选项等。这些知识点将为初学者...
这个压缩包包含了一整套适用于该平台的CMake工具和库,包括可执行文件、库文件、头文件等。 在Linux环境下,使用这个版本的CMake通常涉及以下步骤: 1. 解压文件:首先,你需要使用`tar`命令解压文件,例如: ```...
JESD79-2F DDR2 JESD79-3F DDR3 JESD79-4D DDR4 JESD79-5C DDR5 JESD209-2F LPDDR2 JESD209-3C LPDDR3 JESD209-4E LPDDR4 JESD209-4-1A LPDDR4X JESD209-5C LPDDR5(X)
COMSOL二维光子晶体角态研究:单胞与超胞能带计算及边界态与角态特性分析,COMSOL二维光子晶体角态研究:单胞与超胞能带计算及边界态与角态特性分析,comsol二维光子晶体角态。 单胞能带,超胞能带,边界态以及角态计算。 ,comsol;二维光子晶体;角态;单胞能带;超胞能带;边界态计算,基于Comsol的二维光子晶体角态及能带边界计算研究
六自由度机械臂抓取动作仿真与代码解析:抓取动画、关节参数变化及轨迹图解详解,六自由度机械臂抓取动作仿真指南:掌握两套代码实现动画与轨迹图模拟学习攻略,六自由度机械臂抓取动作仿真-8 两套关于抓取动作的代码,包括抓取动画、关节角、角速度、角加速度的变化仿真、以及抓取轨迹图 简单易懂好上手~ ,六自由度机械臂;抓取动作仿真;抓取动画;关节角变化;角速度角加速度;抓取轨迹图;两套代码;简单易懂好上手,六自由度机械臂抓取动作仿真演示:代码与轨迹图解
ITC网络广播工具软件
Multisim四位密码锁电路仿真设计:设定、开锁与声光报警功能演示资料包,Multisim四位密码锁电路仿真设计:设定、输入、开锁与报警功能详解,附源文件、原理说明书与演示视频,multisim四位密码锁电路仿真设计 功能: 1.通过拨码开关1进行初始密码设定。 2.通过拨码开关2输入密码,实现开锁判断。 3.如果密码正确,LED绿灯亮,表示开锁。 4.如果密码不正确,LED红灯亮,蜂鸣器鸣叫,声光报警。 资料包含:仿真源文件+原理说明书+演示视频 ,四位密码锁电路、Multisim仿真设计、初始密码设定;拨码开关输入;开锁判断;LED灯显示;声光报警;仿真源文件;原理说明书;演示视频,Multisim四位密码锁电路仿真设计:初始密码设置与智能解锁功能的声光报警展示
俗话说,摸鱼摸的好,上班没烦恼,毕竟谁能拒绝带薪拉屎呢(手动狗头) 这是一个云开发职场打工人专属上班摸鱼划水微信小程序源码,没有后台 直接导入微信开发者工具即可运行,UI简约大气漂亮,只需登录微信公众平台配置完合法域名即可轻松上线。 用户进入摸鱼小程序,可以自由设置薪资,上班时间、下班时间、发薪日、 月工作天数以提醒自己摸鱼,全民打酱油,让自己成为摸鱼冠军,《商鞅摸鱼哲学》 摸鱼不是自我放纵,而是个人实力的积蓄,我们的小目标是晚睡晚起 小程序中的今日待办会提醒用户带薪拉屎和闲逛,下方展示的是距离休息日的天数,距离下一次发工资的天数和节日的天数。
【毕业设计】基于Java的开发的一个集合校园二手交易、拼车、失物招领等功能的app_pgj
个人记录:PICkit3离线烧录流程 使用软件:MPLAB X IDE v5.30 记录时间:20250215
基于Matlab代码的电力系统状态估计与实验仿真研究:扩展卡尔曼滤波和无迹卡尔曼滤波在电力系统动态状态估计中的应用及效果分析,Matlab仿真实验研究:基于扩展卡尔曼滤波器与无迹卡尔曼滤波器对电力系统状态估计的影响及验证,状态估计 电力系统状态估计 Matlab代码 实验仿真研究 电力系统由于测量值和传输误差,还有测量噪声的影响,会对状态估计产生影响。 因此,需要对嘈杂的测量进行滤波,以获得准确的电力系统运行动态。 本文使用扩展卡尔曼滤波器(EKF)和无迹卡尔曼滤波器(UKF)来估计电力系统的动态状态。 扩展卡尔曼滤波EKF、无迹卡尔曼滤波UKF 利用扩展的无迹卡尔曼滤波器估计了动力系统的动态状态。 对WECC 3机9总线系统和新英格兰10机39总线系统进行了案例研究。 结果表明EKF和UKF都能准确地估计电力系统的动态状态。 ,核心关键词:状态估计; 电力系统状态估计; Matlab代码; 实验仿真; 测量值误差; 测量噪声; 扩展卡尔曼滤波器(EKF); 无迹卡尔曼滤波器(UKF); 动力系统; 动态状态估计; WECC 3机9总线系统; 新英格兰10机39总线系统。,Matlab
springboot在线考试--
台达DVP EH3与MS300 PLC&变频器通讯程序的全面解决方案,台达DVP EH3与MS300通讯程序:稳定可靠的频率控制与启停管理系统,台达DVP EH3与台达MS300通讯程序(TDEH-9) 可直接用于实际的程序,程序带注释,并附送触摸屏程序,有接线方式和设置,通讯地址说明等。 程序采用轮询,可靠稳定 器件:台达DVP EH3系列PLC,台达MS300系列变频器,昆仑通态7022Ni 功能:实现频率设定,启停控制,实际频率读取,加减速时间设定。 资料:带注释程序,触摸屏程序,接线和设置说明,后续有技术咨询。 ,核心关键词:台达DVP EH3; 台达MS300; 通讯程序(TDEH-9); 轮询; 稳定; 频率设定; 启停控制; 实际频率读取; 加减速时间设定; 触摸屏程序; 接线方式; 设置说明; 技术咨询。,台达PLC与变频器通讯程序(带注释、触摸屏控制)
项目资源包含:可运行源码+sql文件 适用人群:学习不同技术领域的小白或进阶学习者;可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。项目具有较高的学习借鉴价值,也可拿来修改、二次开发。 个人账户管理:支持用户注册、登录与个人信息编辑;提供密码找回及账号安全保护措施。 声纹采集:利用麦克风设备录制用户的声纹样本;支持多种录音格式和质量调整,确保采集到清晰、准确的声纹数据。 声纹模板库管理:建立和维护一个安全的声纹模板库;支持声纹模板的添加、删除、更新和查询操作。 声纹比对与识别:运用深度学习算法对输入的声纹数据进行特征提取和匹配;实现快速、准确的声纹身份验证。 多场景应用支持:适用于多种场景,如门禁系统、移动支付、远程登录等;可根据实际需求定制开发相应的应用场景。 实时监控与报警:实时监控系统运行状态,包括声纹识别成功率、处理速度等指标;当出现异常情况时,及时发出报警信息。 数据分析与报告生成:收集并分析声纹识别过程中的数据,如识别准确率、处理时间等;根据用户需求输出包含详细图表说明的专业级文档供下载打印保存。 社区互动交流:设立论坛版块鼓励用户分享心得体会讨论热点话题;定期邀请行业专家举办线上讲座传授实用技巧知识。 音乐筛选与推荐:集成音乐平台API,根据用户的浏览习惯和情绪状态推荐背景音乐,增强用户体验。 数据可视化:提供交互式的数据可视化面板,使非技术用户也能轻松理解复杂的数据集,从而做出更明智的决策。
三相与多相开绕组永磁同步电机仿真模型的先进控制策略探讨与实现,三相与多相开绕组永磁同步电机的Simulink仿真模型与先进控制策略研究,开绕组电机,开绕组永磁同步电机仿真模型、simulink仿真 共直流母线、独立直流母线,两相容错,三相容错控制,零序电流抑制,控制策略很多 三相开绕组永磁同步电机,六相开绕组永磁同步电机 五相开绕组永磁同步电机,五相开绕组电机 ,开绕组电机; 永磁同步电机仿真模型; simulink仿真; 共直流母线; 独立直流母线; 两相容错; 三相容错控制; 零序电流抑制; 控制策略; 六相开绕组永磁同步电机; 五相开绕组永磁同步电机,开绕组电机仿真研究:共直流母线与独立直流母线的容错控制策略
【毕业设计】基于Java的开发的网上汽车租赁管理系统_pgj
csv 模块是 Python 的标准库,无需额外安装。 运行结果如下图: ['姓名', '年龄', '城市'] ['张三', '25', '北京'] ['李四', '30', '上海'] ['王五', '22', '广州']
【毕业设计】基于Java+Springboot+Vue的宠物领养系统_pgj