INSTALLSHIELD internal library function 9 files and folder functions

zhaozj2021-02-17  58

INSTALLSHIELD internal library function 9 files and folder functions

The file and folder functions provide a comprehensive approach to handle text files, binary files, and folders. Many functions use variable targetdir and srcdir as the path and only accept file names as parameters. Accept the wildcards when appropriate.

Changedirectory

Make the specified directory as the current directory.

Closefile

Close an open file.

CopyFile

Copy a file from one folder to another.

Createdir

Create a new folder.

Createfile

Create a file that specifies the file name.

DeleteDir

Delete a folder.

Deletefile

Delete a file.

Existsdir

Determine if the specified directory exists.

EXISTSDISK

Determine if the specified disk exists.

FileCompare

Compare a file and another.

Filedeleteline

Delete a line in a text file.

Filegrep

Find the specified text in a text file.

FileInsertline

Insert a line in a text file.

FindAllDirs

Find all subfolders under the specified folder.

FindAllFiles

Find all the files in the specified folder matching files and its subfolders.

Findfile

Find the first file that matches a file description in the specified folder.

GetfileInfo

Retrieve the properties, date, time, and size of a file.

Getline

Retrieve a line from an open file.

Openfile

Open an existing file.

Openfilemode

Use the OpenFile function to set the file open.

Readbytes

Read the specified number of bytes from a binarily.

Renamefile

Rename a file.

Seekbytes

Locate the file pointer in a binary file.

SetFileInfo

Set the properties, date and time of a file.

Writebytes

Write the specified number of bytes in the current file pointer position of a binary file.

WriteLine

Write a string into a text file.

XcopyFile

Copy one or more files from one source folder to a destination folder, if specified, including a subfolder.

related functions

Selectdir

See 4.10.

9.1 ChangeDirectory

Grammar: ChangeDirectory (Szpath);

Description: The ChangeDirectory function sets the current directory.

parameter:

Szpath

Specifies the directory name to be set to the current directory. This name can be a fully qualified path name or a UNC path; it must not include a tail with a backslash. If necessary, call ChangeDirectory to call StrremoveLastslash.

return value:

0: ChangeDirectory successfully set the specified directory as the current directory.

<0: ChangeDirectory failed to set the specified directory as the current directory.

annotation:

· Note that after you call ChangeDirectory to set a specified directory to the current directory, this directory cannot be deleted. Before you can delete the directory, you must call ChangeDirectory again to set up a different current directory.

9.2 Closefile

Syntax: Closefile (nvfileHandle);

Note: The Closefile function turns off a file that has been opened by calling OpenFile. After you close a file, you can't read or write the file from it.

parameter:

NVFileHandle

Specifies the handle of the file to be closed.

return value:

0: Indicates that the function is successfully closed.

<0: Indicates that the function failed to turn off the file.

9.3 CopyFile

Syntax: copyfile (szsrcfile, sztargetfile);

Description: The CopyFile function creates a copy of the file specified by the parameter szsrcfile. The new file is specified by the parameter sztargetfile. parameter:

Szsrcfile

Specifies the file name of the file to be copied. If the file name is limited, that is, if it includes a path, CopyFile will copy the file from the specified location. If SZSRCFILE contains an unlimited file name, that is, there is no path information, CopyFile will copy from the path from the system variable Srcdir identifier. To copy a set of files, the wildcard is used in this parameter.

Sztargetfile

Specifies the name of the copy of the file identified by the szsrcfile. If the file name is limited, that is, if it contains a path, CopyFile will copy the file to the location specified by the path. If the szsrcfile contains an unlimited file name, that is, there is no path information, the copy will be created in the directory specified by the system variable targetdir. It will be created if the target directory does not exist.

When a wildcard is included in the file name specified by szsrcfile, the SZTargetFile's file name part is ignored; each source file is copied by its existing name to the path specified by sztargetfile. If the SZTargetFile contains an unlimited file name, the file will be copied to the directory specified by the system variable targetdir. Therefore, CopyFile cannot be used to copy and rename a set of files. When the szsrcfile contains one or more wildcards, the source directory and the target directory must be different.

return value:

0: Indicates that the function is successfully copied from the source directory to the target directory.

<0: Indicates that the function is not copied by one of the following cases:

COPY_ERR_CREATEDIR (-27): The target directory cannot be created. Make sure the path syntax in the Targetdir in the system variable is correct and you have access to the target drive.

Copy_ERR_MEMORY (-6): The function failed to assign the memory required to complete the copy file process. Terminate the running application as much as possible to release memory.

Copy_ERR_NODISKSPACE (-38): The function failed to find enough disk space to copy files on the target drive. Release disk space on the target drive.

COPY_ERR_OPENINPUT (-2): The function failed to open the input file specified by the system variable Srcdir. Ensure that the source file has a valid file name and the source file and the target directory exist.

COPY_ERR_OpenOutput (-3): The function is not copied to copy the file.

COPY_ERR_TARGETREADONLY (-46): The file in Targetdir is a read-only file. Delete the read-only attribute of the target file and try again.

All other negative values: Indicates that some other uncertain errors occur.

annotation:

· If you use unlimited file names and set SRCDIR and Targetdir when using CopyFile, save the current value with VarSave before calling CopyFile and then reset it with a Varrestore. If the target directory does not exist, CopyFile creates it.

· You cannot rename a set of files by calling your CopyFile. However, you can use CopyFile when you have a file.

· To include subdirectory, call the XCopyFile function.

· For file transfer, XcopyFile is a perfect replacement of CopyFile. XcopyFile can make version detection, tag lock. DLL and .exe files to be updated after restarting, and increment the registry access counter for shared .dll and .exe files.

· Because Windows 95 and later do not allow an empty file to be copied, Windows NT does not allow you to create empty files, and CopyFile will not work when these platforms are used to copy empty files (SIZE = 0kb). · After modifying the .ini file with WriteProfstring or WriteProfint, under Windows 95 and later, you must refresh the cache before using CopyFile. All .INI files are placed in a cache in Windows 95 and later; this feature may cause delays to write to the specified file. This can then prevent subsequent file operations. To avoid this problem, simply call WRITEPROFSTRING with empty parameters to write data to .ini files immediately, as shown below:

WriteProfstring ("C: //Test.ini", "Windows", "KeyboardDelay", "100");

File: // null string (") for All Four Parameters

WriteProfstring (",", ",", "");

File: // CopyFile Should Now Have Access To Updated File.

CopyFile ("c: //test.ini", "c: //temp/test.ini");

9.4 Createdir

Syntax: CreateDir (SZDirPath);

Description: The CREATEDIR function creates one or more subdirectories on the target drive. You can use a path containing multi-layer subdirectory, such as C: / Programs / WinApps / MyApp. Creatir will create it in any subdirectory that does not exist in any path. For example, if C: / Programs / WinAPPS and C: / Programs / WinAPPS / MyApp do not exist, these subdirectories are created by Creatdir.

parameter:

SZDirPath

Specifies the fully qualified path to the subdirectory to be created. Separate each layer in the path (by using a backslash escost (//)).

return value:

0: Indicates that the function successfully created a specified directory or specifies the directory already exists on the target drive.

<0: Indicates that the specified directory does not exist and the function failed to create a specified it.

annotation:

Creatdir will fail in the following cases:

Path illegal;

Any subdirectory on the drive or path is written;

The drive name is invalid;

You don't have a network privilege to create a subdirectory.

9.5 CREATEFILE

Syntax: CreateFile (nvfileHandle, Szpath, SzFileName);

Description: The createfile function creates a new file. If the same name is already existing, createfile changes it. You must use OpenFileMode to set file mode with OpenFileMode before you create a file with CreateFile.

CreateFile opens the newly created file to read / write (binary) or add (text file), so you can use other functions, such as getline, readbytes, write, and writebytes. Come to read or write from the file.

In addition to reading / writing or adding, all new creation files are automatically opened to OF_SHARE_DENY_NONE mode. This means that the file is opened to read or write it to other programs. The root segment of this approach is recorded in the Windows OpenFile API. When you end read from a file or write it, you must use the CloseFile function to turn the file. parameter:

NVFileHandle

Returns the handle of the new file.

Szpath

Specifies the full-qualified path for the new file to create the subdirectory.

SZFileName

Specifies the file name of the created file.

return value:

0: Indicates that the function successfully created a new file.

<0: Indicates that the function failed to create a new file.

annotation:

· CREATEFILE Create a new file and open it so that you can read or write it in a new file. To write into an existing file, you must first open the file in file_mode_append mode with the OpenFileMode and OpenFile functions.

• When the operation log is activated, the cretefile function operation does not deposit into the uninstall record. If you want a file created by CreatFile to the uninstall record, use XCopyFile to transfer a launcher file (with your file name) to the target system when the deposited function is activated. You use Enable and Disable functions to activate and disable storage. When the storage feature is activated, the XCopyFile operation is deposited. After the startup file is deposited, you can write or override the stored launcher file using CreatFile and other file-related functions. The file name must remain unchanged, otherwise it will not be found in the uninstall record.

9.6 DeleteDir

Syntax: deletedir (szdir, nflag);

Note: The deletedir function deletes a subdirectory. Depending on your value used in the parameter nflag, you can delete it only if the child directory is empty, even if the subdirectory contains files, or deletes the entire root directory. Setting NFLAG must be particularly cautious.

parameter:

SZDir

Specifies the full qualification of the directory to be deleted.

Nflag

Specify the delete option. One of the following predefined constants in this parameter location:

AllContents: Delete the directory specified by SZDIR, including all subdirectories and files below. The directory you deleted must be a subdirectory and cannot be a root directory on the drive.

ONLYDIR: Delete it only when the directory specified by SZDIR is empty. Otherwise the function fails.

Root: Even if the directory specified by SZDIR is the root directory, you have to delete it. If SZDir is an root directory, DeleteDir will delete everything on the disk.

return value:

0: Indicates that the function successfully deletes the subdirectory.

<0: Indicates that the function failed to delete the subdirectory.

annotation:

· You can't delete the current directory.

· You can't delete a file you don't have right on a network system.

· DELETEDIR cannot delete read-only, hidden, or system files.

· If deletedir encounters a read-only file, the function may fail after some files in the subdirectory.

9.7 Deletefile

Syntax: deletefile (SZFILE);

Description: The deletefile function deletes one or more files. Note that deletefile can't delete read-only, hidden, or system files. This function does not work if you try to delete a file that you don't have the right file right on a network system.

parameter:

SZFile

Specifies the name of the file to be deleted. If SZFILE specifies a full-qualified name, that is, including a path, DeleteFile will delete the file from the specified directory. If SZFILE contains an unlimited file name, that is, there is no path information, deletefile will remove files from the directory specified by the system variable targetdir. Multiple files can be deleted in SZFILE. return value:

0: Indicates that the function successfully deletes the specified file.

<0: Indicates that the function failed to delete the specified file.

annotation:

You can use wildcard when you use FindFile, then use deletefile to delete them.

9.8 EXISTSDIR

Syntax: existsdir (szpath);

Description: The existsdir function detects the existence of the specified directory on the target system.

parameter:

Szpath

Specifies the fully qualified path to the directory you want to find on the target system.

return value:

EXISTS (0): Indicates that the specified directory is in the target system.

NOTEXISTS (-1): Indicates that the specified directory is not in the target system.

9.9 EXISTSDISK

Syntax: EXISTSDISK (SZDisk);

Note: The existsdisk function detects the existence of the specified disk drive on the target system.

parameter:

Szdisk

Specify the disk drive character.

return value:

EXISTS (0): Indicates that there is a specified drive on the target system.

NOTEXISTS (-1): Indicates that there is no specified drive on the target system.

9.10 FileCompare

Syntax: FileCompare (SZFileName1, SzFileName2, Ncompareflag);

Description: The FileCompare function compares the size, date, or version of the two files.

parameter:

SZFileName1

Specifies the full qualification of the first file to be compared.

SZFileName2

Specifies the full qualification of the second file to be compared.

Ncompareflag

Specifies the comparison option. One of the following predefined constants in this parameter location:

Compare_size: Compare the size of two files.

Compare_date: Compares the date of the two files.

Compare_version: Compare the version of the two files.

return value:

Equals (2): The date, size, or version of the first file and the second are equal.

FILE_NOT_FOUND (-2): The function failed to find a file or failed to find it.

Greater_than (0): The first file is updated or larger than the second file, according to the constant used in the parameter ncompareflag:

. Compare_version

Document is new than files.

. Compare_date

The file is one more than two days.

. Compare_size

The file is one larger than the file.

. Less_than (1)

The file is one more than file two or small.

Other_failure (-1)

Uncertain mistakes occur.

9.11 FILEDELETELINE

Syntax: FileDeleteline (SZFileName, NStartLinenum, Nendlinenum);

Note: The FileDeleteLine function uses a line of starting lines and end line rows from a text file (including the starting line and end line). This function acts on a line-oriented text file; it does not work on binary files. You can use the FileDeleteline and FileGrep functions to find and delete the text line in a file.

The file specified by SZFileName must have not been opened by calling OpenFile. If the SZFileName has been opened, call FileDeleteLine to call Closefile. parameter:

SZFileName

Specify the full qualification of the file, which is located in the directory specified by the system variable Srcdir. If the file exists, the row specified by NStartLinenum and NendLineNum will be removed from the file.

NStartLinenum

Specifies the line number to be removed from the file. Note the line from 0 start numbers.

Nendlinenum

Specifies the line number of the last line to be removed from the file. Note the line from 0 start numbers. In order to delete the file end from the row specified from NStartLineNum, the predefined constant delete_eof is delivered to this parameter.

return value:

0: FileDeleteline successfully deletes the specified line from the file.

<0: FileDeleteline failed because one of the following conditions:

FILE_NOT_FOUND (-2): InstallShield failed to find the file specified by SZFileName.

File_rd_only (-5): The file is written.

LINE_NUMBER (-7): A line number you specify less than 0, or there is no line number in the file.

OUT_OF_DISK_SPACE (-6): There is not enough disk drive space to complete the specified operation.

Other_failure (-1): Other uncertain errors occur.

9.12 FileGrep

Syntax: FileGrep (SZFileName, Szsearchstr, Svreturnline, NVLINENUMBER, NFLAG);

Note: The FileGrep function looks for a specified string in a text file. If the string is found, the row containing the string is returned to the parameter svreturnline, and the line number of the row is returned to the parameter nVLINEnumber. Finding is not case sensitive. FileGrep acts on a line-oriented text file; it does not work on binary files.

It is not necessary to open it before looking for a file with FileGrep; you do not need to close it after calling FileGrep. The file open and file closes are automatically executed by FileGrep. Although in most cases, FileGrep will be executed successfully on a file that has been opened (previously called OpenFile), but if the file is opened in an addition mode, FileGrep will return file_not_found.

parameter:

SZFileName

Specifies the full qualification of the file to be found.

Szsearchstr

Specify a string lookup.

Svreturnline

Returns the row found by Szsearchstr.

NVLineNumber

Returns the line number of the row found by Szsearchstr. The line starts numbered in 0.

Nflag

Specify the lookup option. One of the following predefined constants in this parameter location:

Continue: Retrieves the next appearance of the lookup string (if any).

Restart: The first appearance of retrieving the lookup string.

return value:

0: FileGrep finds the specified string.

<0: Filegrep failed because of one of the following:

END_OF_FILE (-4): Did not find a lookup string to the end of the file.

FILE_NOT_FOUND (-2): InstallShield failed to find the file specified by SZFileName.

FILE_LINE_LENGTH (-3): The maximum length allowed exceeds the allowed length.

Other_failure (-1): An uncertain error occurs.

9.13 FileInsertline

Syntax: FileInsertline (SZFileName, SzIset, NLINENUMBER, NINSERTFLAG); Description: The FileInsertLine function is inserted or replaced by the specified line number. You can use FileInsertLine and FileGrep, FileGrep find the line and return the line number.

FileInsertline works in a line-oriented and a text file that does not exceed 1,024 bytes per line. InstallShield assumes that the row longer than the maximum allowable length indicates that this is a binary and causing FileInsertLine to fail.

The file specified by SZFileName must have not been opened by calling OpenFile. If the SZFileName has been opened, the Closefile is called before calling FileInsertline.

parameter:

SZFileName

Specify the full qualification of the file, which is located in the directory specified by the system variable Srcdir. If the file exists, insert the value of SzInsertline.

Szinsertline

Specifies the string inserted into the file.

NLINENUMBER

Specify the line number you want to insert SzInsertline. The first line number is 0.

Ninsertflag

Specify an insertion location option. One of the following predefined constants in this parameter location:

Before: Insert before NLINENUMBER.

After: Insert after nLINENUMBER.

Append; add SZInsertLine to the row specified by NLINENUMBER.

Replace: Use SzInsertline to replace the rows specified by NLINENUMBER.

return value:

0: FileInsertline successfully inserts a line to the specified file.

FILE_LINE_LENGTH (-3): Indicates the maximum length allowed by the leader over the text file.

FILE_NOT_FOUND (-2): FileInsertline failed to find the file specified by SZFileName.

FILE_RD_ONLY (-5): Indicates that file write protection.

LINE_NUMBER (-7): Indicates that one of the line numbers you specify is less than 0, or there is no line number in the file.

OUT_OF_DISK_SPACE (-6): Indicates that there is not enough disk drive space to complete the specified operation.

Other_failure (-1): An uncertain error occurs.

9.14 FindAllDirs

Syntax: FindAllDirs (SZDIR, NOP, LISTDIRS);

Note: FindAllDirs look up the structure of the entire disk or directory and returns a list of strings for a sub-directory. If the NOP is include_subdir, look up starting from the directory specified by SZDIR and proceeds to the subdirectories.

parameter:

SZDir

Specify the directory name of the lookup.

NOP

Specifies whether you want to find all the subdirectories under SZDIR. One of the following predefined constants in this parameter location:

Exclude_subdir: Does not include subdirectory.

INCLUDE_SUBDIR: Includes subdirectory.

Listdirs

Returns the list of fully qualified directory names. The list of strings identified by the ListDirs must have been initialized by calling ListCreat.

return value:

0: FindAllDirs successfully generates a list of subdirectory names.

<0: FindAllDirs failed to generate a list.

annotation:

· FindAllDirs start looking for a layered subdirectory structure from the specified directory. If the specified directory is an root directory and the NOP contains include_subdir, all directory names on the entire disk are returned. You can use FindAllDirs to find a subdirectory for a specific directory, or you can use it to find all directories on a disk.

9.15 FindAllFiles Syntax: FindAllFiles (SZDIR, SZFileName, SvResult, NOP);

Description: The FindAllFiles function looks up a single subdirectory structure and returns the file name of the first file with a specific file description. If the change of the NOP is RESET, INSTALLSHIELD starts looking up in the directory specified by the parameter szdir and continues to find in its subdirectory structure until it finds a file that matches the SZFileName. If the NOP is equal to Continue, lookups continue to leave from the function last time called. Repeat the function to find all files that appear with SZFileName.

parameter:

SZDir

Specify the name of the directory you want to find.

SZFileName

Specify the file description to find. This parameter allows wildcards.

SvResult

If found, return the list of the first matching file. If FindAllFiles fails, Svresult remains unchanged.

NOP

Indicates the lookup option. One of the following predefined constants in this parameter location:

Continue: Continue to find in the previous lookup stop.

RESET: Start looking up at the beginning of the directory specified by SZDIR.

Cancel: Release all files and folders that you have previously called when FindAllFiles. In the installation under Windows NT, you call FindAllFiles with this parameter to ensure that subsequent files that have been accessed by FindAllFiles are successful.

To find all files that match the file description, you can follow the steps:

The folder to look up is assigned to SZDir.

Assign the file to SZFileName, such as is5 * .txt.

Set the NOP to RESET and call FindAllFiles.

When the return code of FindAllFiles is 0, save the file name returned by SvResult; then call FindAllFiles, and the NOP is set to Continue ..

Finally, running in the installation under Windows NT, call FindAllFiles, NOP Set to Cancel

return value:

0: Indicates that the function retrieves and returns a file that matches the description.

<0: Indicates that the function failed to find a file that matches the description.

annotation:

· This function starts to find a layered subdirectory structure from the specified directory. If the specified directory is an root directory, installshiled looks for the entire disk. The function stops at the first match file name it finds.

· First time you call this function to start a new lookup, set the NOP to RESET. You can continue looking up all other appearances of the specified file by setting the NOP to Continue and you can call the function call in a loop, and the FindAllFiles function fails to end.

· You cannot use the XcopyFile function in a FindAllFiles (..., reset) and the FindAllFiles (..., Continue) loop. If you call XcopyFile in a FindAllFiles loop, the file name returned by FindAllFiles (..., Continue) may be incorrect.

9.16 Findfile

Syntax: Findfile (Szpath, SzFileName, SvResult);

Note: The FindFile function looks for a specified file in a directory. InstallShield Returns the first matching file in the parameter svresult.

parameter:

Szpath

Specify the name of the directory you want to find. The subdirectory in this directory is not found.

SZFileName

Specify the file name to look for. This parameter allows wildcards.

SvResult

Returns the file name of the first file that matches SZFileName. This parameter contains unlimited file names (that is, do not include drive indicators and paths).

Return value: 0: Indicates that the function successfully found and returned to the specified file.

<0: Indicates that the function failed to find a file.

annotation:

· This function only finds the specified subdirectory. It does not look for the entire disk or directory tree.

9.17 getFileinfo

Syntax: getfileinfo (Szpathname, NTYPE, NVRESULT, SVRESULT);

Description: Call the getFileInfo function to determine the properties, date, time, or size of a file. In each getFileInfo statement, you can only ask one of these data items. For example, in order to get the date and time information of a file, you must call getfileinfo twice, once a date, take time.

parameter:

Szpathname

Specify the full qualification of the file you want to retrieve it.

NTYPE

Specifies the type of information to retrieve. If the information is a number, getfileinfo put it in NVResult. If the information is a string, getfileInfo put it on the svresult. One of the following predefined constants in this parameter location:

File_attribute: The file properties are returned in NVRESULT. Note.

File_date: The file date returns to SvResult in YYYY / MM / DD format.

File_size: The size is returned to NVRESULT in bytes.

File_time: The file time is returned to SvResult in hh: mm: SS format.

NVRESULT

Returns numeric information.

SvResult

Returns the string information.

return value:

0: Indicates that the function successfully retrieves the required file information.

<0: Indicates that the function failed to retrieve the required file information.

annotation:

• After calling getFileInfo, use the IF-THEN-ELSE logic to determine the file attribute after calling getFileInfo with File_Attribute. If nvresult = file_attr_normal, then the file properties are set. If NVRESULT <> file_attr_normal, the NVRESULT and one or more file attribute constants are used to determine which properties set.

IF (nvresult = file_attr_normal) THEN

File: // The file is normal.

Else

IF (file_attr_hidden& nvresult) THEN

File: // The file is hidden.

Endif;

IF (file_attr_readonly & nvresult) THEN

File: // The file is read-only.

Endif;

Endif;

9.18 getLine

Grammar: getLine (nvfileHandle, SVline);

Note: The getLine function reads a line from a text file that is read in a read-only mode. Before you call GetLine, you must first call OpenFileMode to set the file mode for read-only, then call OpenFile to open the file. Read the first line of text from the file from the file for the first call of GetLine. After reading a line, Getline repositions the file pointer to the next line. Read the second line for the second call of GetLine, so continued. Getline removes the carriage return and wrap characters from the row it returns.

For a text file, use the WriteLine function. WriteLine always generates a row with a carriage return and wrap characters at the end of the line.

parameter:

NVFileHandle

Specifies the handle that has already been opened by calling OpenFile.

SVLINE

Returns a line of text returned from the file specified by NVFileHandle. return value:

0: Indicates that the function successfully retrieves a line of text from an open text file.

<0: Indicates that the function fails because of the file tail or other error. This situation also indicates that getLine has read all rows in the file.

annotation:

· The maximum length of a row is 4,096 characters. Read multiple rows from a file, each read a line is individually calling a getLine or put the getLine statement in a loop.

• When GetLine has read all lines in the file, return a file end (end-file). Note If you open a file in an add-time, you will fail when you call the getLine function, because the file pointer is at the end of the file. If the file specified by NVFileHandle is opened in binary, the function will fail.

9.19 OpenFile

Syntax: OpenFile (nvfileHandle, Szpath, SzFileName);

Description: The OpenFile function opens a text file or binary. Before you open this file, you must set the file mode by calling OpenFileMode.

After you open a text file, call GetLine and WriteLine to read and write files. After you open a binary file, call ReadBytes and Writebytes to read and write files. Before writing a binary file, you may need to use Seekbytes to locate the file pointer.

You can also use FileGrep, FileInsertline, and FileDeleteLine functions to find, read, and write text files. However, these functions do not require you to open or close files (this is internal processing). According to your needs, these functions can provide you better service. When you complete the read or write to a file with getLine or WriteLine, you must call the Closefile function to close the file.

Use CREATEFILE to create a file. CreateFile opens a new file with an add mode (text file) or read / write mode (binary).

parameter:

NVFileHandle

Returns the handle of the opened file. When you call other file-related functions in InstallShield, use this handle to identify the file.

Szpath

Specify the path to the file you want to open (possibly containing a drive indicator).

SZFileName

Specifies the unlimited name of the file you want to open (that is, there is no drive indicator or path).

return value:

0: Indicates that the function is successfully opened.

<0: Indicates that the function failed to open the file.

9.20 OpenFileMode

Grammar: OpenFileMode (nmode);

Description: The OpenFileMode function sets the way you want to open or create. You pass the change of the parameter nmode to one of the following:

Text file is an add mode;

Text file is read-only;

Binary files are read / write methods;

Binary files are read-only.

Once you set the file mode, call OpenFile to open an existing file or call CREATEFILE to create and open a new file.

parameter:

nmode

Specify how to open a file. One of the following predefined constants in this parameter location:

FILE_MODE_APPEND: This constant allows a text file to be opened or created in an addition method. When a file is opened by OpenFile, the file pointer is at the end of the file. You can add a line to the file using the WriteLine function. The file created with CREATEFILE is new (empty), so the line added to the file is written to the beginning of the file. Note If you open a file in an addition method, if you call the getLine function, it will fail because the file pointer is at the end of the file. FILE_MODE_NORMAL: This constant allows a text file to be opened in a read-only mode. When a file is opened by OpenFile in a read-only mode, the file pointer is in the file header. You can use the getLine function to read the file. When file_mode_normal is valid, the file created with CREATEFILE will actually be created in file_mode_append mode.

FILE_MODE_BINARY: This constant allows a binary to be opened or created in read / write. When you open or create a binary file with OpenFile or CreateFile, you can call ReadBytes from the file read and call WriteBytes to write this file. When writing to a binary file, starting from the current file pointer position, files for a newly opened or created is 0, that is, the beginning of the file. If you want to add a binary that opens with OpenFile, you must use Seekbytes to locate the file pointer before writing. To open a CD-ROM or a file on a read-only drive, call OpenFileMode to set the file mode for read-only (file_mode_binaryreadonly).

File_Mode_binaryReadonly: This constant is similar to the file_mode_binary constant, except that it opens the binary file in a read-only mode. When you open a binary file on the CD-ROM or the read-only drive, use this constant to open a binary. File_Mode_binary failed when opening a binary file on a CD-ROM or a read-only drive.

return value:

0: Indicates that the function is successfully set.

<0: Indicates that the function failed to set a file mode.

9.21 ReadBytes

Syntax: Readbytes (NfileHandle, SvString, NINDEX, NBYTES);

Description: The ReadBytes function starts reading the specified number of bytes from a file pointer from a file. When the function returns, INSTALLSHIELD relocates the file pointer to the end position of the read byte from the file.

You must call OpenFileMode and OpenFile to open the file in binary before you can read it.

The parameter NINDEX is the subscript in the value specified by SVString. Use the parameter nbytes to specify how many bytes starting from the parameter nindex specified from the parameter NINDEX. If Nindex plus NBYTES is greater than the length of svstring, only the number of bytes starting to the string end to the end of the string from the file. For example, if the svstring is declared to 100 bytes long, the parameter NINDEX is declared to 50 bytes, and the parameter nbytes is 75 bytes, and only the bytes between 49 and 99 (50 bytes, not 75 bytes). Read it.

parameter:

NfileHandle

Specifies the file handle of files that open in binary.

Svstring

Returns the byte read from the file. Variables passing to this parameter must have been declared as explicit size, and it must be large enough to accommodate by nBytes specified bytes.

Nindex

Specifies one of the subscripts in the svstring; the data in the file is inserted into the string in this position.

Nbytes

Specifies the number of bytes read from the file. Bytes begin to read from the file pointer. When the byte is read, the InstallShield repositions the file pointer. return value:

X: Indicates that the function successfully read bytes from the file, X is the number of bytes that actually returns to svstring.

<0: Indicates that the function failed to read bytes from the file.

9.22 renamefile

Syntax: renamefile (szsrcfile, sztargetfile);

Description: The renamefile function modifies the file name and / or moves a file from a directory to another.

parameter:

Szsrcfile

Specifies the file name of the file to be renamed or moving. If szsrcfile specifies a full qualification, that is, if it includes a path, renamefile will change the file in the specified directory. If the szsrcfile contains an unlimited name, that is, there is no path information, renamefile will be renamed or moved to the file in the directory specified by the system variable Srcdir. Note that wildcards are not allowed; each call RenameFile can only rename or move a file.

Sztargetfile

Specify a new name and / or new location for the file. If SZTARGETFILE specifies a full qualification, that is, if it includes a path, renamefile will rename or move files to the specified directory. If the sztargetfile contains an unlimited name, that is, there is no path information, renamefile reamerled the file to the directory specified by the system variable Srcdir. Look at the following annotations.

return value:

0: Indicates that the function successfully modifies the file name or moving file.

<0: Indicates that the function failed to modify the file name or mobile file.

annotation:

• If SZSRCFILE and SZTARGETFILE point to the same directory (or when using unlimited names, srcdir and targetdir points to the same directory), the file specified by szsrcfile will be renamed unless the file specified by the SZTARGETFILE has exist in this directory.

• If SZSRCFILE and SZTARGETFILE point to different directories (or when using unlimited names, srcdir and targetdir points to different directories), the files specified by szsrcfile will be moved to the new directory and named the name specified by sztargetfile unless specified by SztargetFile. The file already exists in this directory.

9.23 seekbytes

Syntax: Seekbytes (NfileHandle, Nbytes, NPosition);

Description: The Seekbytes function repositions the file pointer in an open binary. You can move file pointers with respect to the current location or with the file header or tail one specific byte number. Before calling Seekbytes, you must open the file in binary by OpenFileMode and OpenFile. When you end the write byte to the file, call Closefile to close the file.

parameter:

NfileHandle

Specifies the file handle of files that open in binary.

Nbytes

Specifies the number of bytes that the file pointer to move relative to the nPosition specified. If nbytes is an integer, the file pointer moves to the file. If Nbytes is a negative number, the file pointer moves to the file.

NPosition

Specify the location in the file, the pointer moves NBYTES from this location. One of the following predefined constants in this parameter location:

FILE_BIN_CUR: Start the pointer from the current location to move NBYTES.

File_bin_end: Start Pointer from the File Tail Move Nbytes.

FILE_BIN_START: Start Pointer from the file header to move NBYTES. return value:

0: Indicates that the function is successfully repositioning the pointer.

<0: Indicates that the function failed to reposition the pointer.

9.24 Selectdir

See 4.10.

9.25 SetFileInfo

Syntax: SetFileInfo (Szpathfile, NTYPE, NATTRIBUTE, SZVALUE);

Description: The setFileinfo function sets the date or time of an existing file, or modifies the properties of the file. To modify the date and time of a file, you must call setfileinfo twice, modify the date, and modify the time. However, you can set the multiple properties of the file with the setFileinfo once in the parameter Nattribute position, only the setfileinfo is used to set the setfileinfo once.

parameter:

Szpathfile

Specify the list of files that you want to modify the files of its date, time, or attribute.

NTYPE

Specifies the file feature to modify. One of the following predefined constants in this parameter location:

FILE_ATTRIBUTE: Indicates one or more properties of the file will be modified.

FILE_DATE: Indicates that the date of the file will be modified.

FILE_TIME: Indicates that the time will be modified.

Nattribute

When NTYPE is file_attribute, specify the file attribute (transfer 0 when NTYPE is file_date or file_time). To specify multiple file properties, combine the following predefined constants or operators (|):

FILE_ATTR_ARCHIVED: Set the archive attribute.

File_attr_hidden: Sets the hidden properties.

FILE_ATTR_READOONLY: Sets read-only properties.

FILE_ATTR_SYSTEM: Set the system properties.

FILE_ATTR_NORMAL: When the constant is specified separately, all file properties are cleared. When this constant and other file attribute constants or operator combine, those that do not include or the properties in the expression are cleared.

SzValue

Specify one of the following:

When NTYPE is file_date, a date is specified in YYYY / MM / DD or YYYY / MM / DD format. This date must not be earlier than "1980/01/01". When using a backslash as a separator, remember that a backslash is inserted into a string as a escape character, such as "1980 // 01 // 01".

When NTYPE is file_time, specify a time in hh: mm: SS format, use a 24-HOUR clock format; note the number of seconds must be a multiple of 2.

When NTYPE is File_Attribute, the parameter passes an empty string.

return value:

0: Indicates that the function successfully sets the date, time, or attribute of the file.

<0: Indicates the date, time, or attribute that the function is not set.

9.26 Writebytes

Syntax: Writebytes (Nfile, svstring, nindex, nbytes);

Description: The WriteBytes function writes the specified number of bytes to a file that opens in binary. This function starts writing bytes from the file pointer. Before calling Writebytes, you must call OpenFileMode (file_mode_binary) to open the file, then call OpenFile..

The parameter NINDEX is the subscript in the svstring. Use the parameter nbytes to specify how many bytes starting from the parameter NINDEX specified. If Nindex plus NBYTES's value greater than the length of svstring, installShield only writes the bit number of the specified subscript to the end of the string to the file. For example, if the svstring is declared to 100 bytes long, the parameter nindex is 50, the parameter nbytes is 75, and only the bytes of 51 to 100 (50 bytes, rather than 75 bytes) are written to the file. in. parameter:

nfile

Specifies the file handle of files that open in binary.

Svstring

Specifies a string variable that contains the byte to be written to the output file.

Nindex

Specifies a subscript in the svstring; the byte starting from this location is written to the output file. Note that the first byte is in the subscript position 0.

Nbytes

Specify the number of bytes you want to write to the output file.

return value:

X: X is the number of bytes that are actually written.

<0: Indicates that the function failed to write these bytes.

9.27 WriteLine

Syntax: WriteLine (nvfilehandle, szline);

Description: The WriteLine function writes a line of text to a text file that is opened in an add mode. Before calling WRITELINE, you must first use the OpenFileMode to set file mode as adding mode, then create a file with CREATEFILE, or open the file with OpenFile. This function is placed in the end of the file.

WriteLine has a row of carriage return and wrap. For a binary file, use Writebytes.

This function does not work in a read-only mode.

parameter:

NVFileHandle

Specify a file handle that opens the file. The handle is obtained from the OpenFile or CreateFile.

Szline

Specifies the string that contains the text to be written to the file.

"One" and "this":

Don't try to write multi-line by embedding a newline in a string you pass to Szline. The following code writes the string as a row, with a non-printing character between "One" and "this":

Szstring = "this is line one / nthis is two";

WriteLine (nvfilehandle, szstring);

Come only call WriteLine once and write two lines, you have to insert a return and a newline (in this order):

Szstring = "this is line one / r / nthis is two";

return value:

0: Indicates that the function is successfully written to the file.

<0: Indicates that the function failed to write the line to the file.

annotation:

· You can embed double quotes in a string by separating strings with single quotes. For example, if you want to write a string "this String Contains a Double" Quotation Mark. ", You can use the following code:

Writeline (NVFileHandle, 'this string contains a double "quotation mark.");

9.28 xcopyfile

Syntax: XcopyFile (Szsrcfile, SztargetPath, NOP);

Description: XcopyFile functions copy one or more files from the source directory to the target directory. This function can also copy the bibos directory like a copy file. When constant include_subdir is passed to the parameter NOP, if necessary, XcopyFile creates a subdirectory on the target directory. You can't rename files with xcopyfile. Rename a file in the file copy operation, use the CopyFile function.

parameter:

Szsrcfile

Specify the file to be copied. If the file name is limited, that is, if it includes a path, XcopyFile will copy files from the specified location. If SZSRCFILE contains an unlimited file name, that is, there is no path information, CopyFile will copy from the path from the system variable Srcdir identifier. To copy multiple files, the wildcard is used in this parameter location.

SztargetPath

Specifies the directory to be copied by the file specified by szsrcfile. If this parameter contains an empty string, the file will be copied to the directory specified by the system variable targetdir.

NOP

Specifies the type of copy to be executed. One of the following predefined constants in this parameter location is passed. To specify multiple options, combined with or operator combination constants:

COMP_NORMAL: Copy files to target systems, update files for existing same names, do not consider dates, time, or version information.

Comp_update_same: Update file, even if the date, time or version of the source file is the same as the target file. You must also specify comp_update_date or comp_update_ version together with this constant, otherwise InstallShield ignores the constant.

Comp_update_date: Update files based on file dates and time. If the source file is more than the target file, the constant updates the file.

Comp_update_version: Update the file based on the file version. If the source file is more than the target file, the constant updates the file. If the source file and the target file do not exist file versions, the date and time is compared. If only one file does not exist file versions, INSTALLSHIELD assumes that the file containing version information is a newer file.

Selfregister: When you use the "non-batch method" to install the self-registration file, you will immediately perform the self-registration process.

When you have called Enable (SelfregisterBatch), this option will queue the registration file waiting for registration. When you use the "Batch Method" to install the self-registration file, these files are registered once the DO (SelfregistrationProcess) is called. Always use the Selfregister and constant sharedfiles with a bit or operator combination.

SharedFile: Handle the shared and lock file processing, updating the XcopyFile to process all files to shared and tag lock. Download. View RebootDialog and SDFINISHREBOOT. The sharedfile option causes XcopyFile to process all files as a shared file, and when the file exists in the target directory and has a access counter greater than 0, the registry access counter is automatically incremented. If the shared file does not exist when the target directory does not access the counter, installShield creates the counter and sets it to 1. If the shared file already exists in the target directory but does not access the counter, INSTALLSHIELD creates the counter and initials to 2 as a preventive measures to prevent accidental deletion during the uninstall.

LockedFile: The XCopyFile tag is locked .dll and .exe file to be updated when Windows or system restarts. A locked file is a file that is being used by an application or system when InstallShield is trying to access or update. Likedfile options work like SharedFile, except for LockedFile does not create a registry expression or modify the registry access counter. You cannot use the lockedfile option when you use the sharedfile option. There are some non-shared files that do not register their feet and access counters for their script. These files will never be uninstalled unless they are used by the application itself. LockedFile allows XcopyFile to handle non-shared lock files. Exclude_subdir: Specifies the subdirectories that are not included in the source path.

INCLUDE_SUBDIR: Specifies the subdirectory under the source path must also be copied.

return value:

0: Indicates that the function is successfully copied.

<0: Indicates that the function is not copied by one of the following conditions:

COPY_ERR_CREATEDIR (-27): The target directory cannot be created. Make sure the path syntax in the Targetdir in the system variable is correct and you have access to the target drive.

Copy_ERR_MEMORY (-6): The function failed to assign the memory required to complete the copy file process. Terminate the running application as much as possible to release memory.

Copy_ERR_NODISKSPACE (-38): The function failed to find enough disk space to copy files on the target drive. Release disk space on the target drive.

COPY_ERR_OPENINPUT (-2): The function failed to open the input file specified by the system variable Srcdir. Ensure that the source file has a valid file name and the source file and the target directory exist.

COPY_ERR_OpenOutput (-3): The function is not copied to copy the file.

COPY_ERR_TARGETREADONLY (-46): The file in Targetdir is a read-only file. Delete the read-only attribute of the target file and try again.

-51: A self-registration file is not successfully registered.

All other negative values: Indicates that some other undetermined errors occur.

annotation:

· When using XcopyFile, if you use unlimited file names and set values ​​for srcdir and Targetdir, call VARSAVE to save the current value before calling XcopyFile, and then restore them with Varrestore.

• Because Windows 95 and later do not allow an empty file to be copied, Windows NT does not allow you to create empty files, XcopyFile will not work when it is used to copy empty files (size = 0kb) under these platforms.

• After modifying the .ini file with WriteProfstring. After Windows 95 and later, you must refresh the cache before using XcopyFile. All .INI files are placed in a cache in Windows 95 and later; this feature may cause delays to write to the specified file. This can then prevent subsequent file operations. To avoid this problem, simply call WRITEPROFSTRING with empty parameters to enforce the data to the .ini file immediately, as shown below:

WriteProfstring ("C: //Test.ini", "Windows", "KeyboardDelay", "100");

WriteProfstring (",", ",", "");

File: // null string (") for All Four Parameters

File: // XcopyFile Should Now Have Access to Updated File.

转载请注明原文地址:https://www.9cbs.com/read-30518.html

New Post(0)