Overview of Other API Functions for File Management

Here, I'll briefly consider some API functions that relate to file management and that I have not covered in detail yet.

  • CreateDirectory Using this function, it is possible to create a directory. The function accepts two parameters. The first parameter points to the string containing the name of the directory being created, and the second parameter is the pointer to the security attribute (more details on this attribute will be provided later in this chapter). Usually, the second parameter is assumed to be zero.

  • RemoveDirectory This function deletes directories. The only parameter of this function is the address of the string containing the name of the directory to be deleted. The directory must be empty for the function to succeed.

  • SetCurrentDirectory This function sets the current directory. The parameter of this function is the address of the string that contains the directory name. Note that every partition can have its own current directory.

  • GetCurrentDirectory Using this function, it is possible to get the current directory. The function accepts two parameters. The first parameter must be equal to the buffer length for the current directory string. It is assumed that the string will be zero- terminated . Consequently, the buffer length must take the trailing 0 character into account when the length is computed. The second parameter is the address of the string (buffer), into which the name of the current directory will be placed.

  • DeleteFile This function deletes the specified file. The only parameter of this function must contain the address of the string that defines the filename. The function will fail if the file is open or has an attribute that doesn't allow deletion.

  • CopyFile This is the function for copying files. The first parameter is the address of the string containing the name of the file being copied . The second parameter points to the string containing the name of the new file. The third parameter defines the function behavior if the file with the specified name already exists in the specified directory. If the value of this parameter is 0, then the existing file will be overwritten. If this parameter has a nonzero value, the function won't overwrite the existing file.

  • MoveFile This function moves the file or directory with subdirectories. The first argument of this function is the name of file or directory, and the second argument is the new name of the file or directory.

  • MoveFileEx This function moves the file or directory, taking into account the third argument value. The first two arguments are the old name of file or directory and the new name of the file or directory, respectively. The third argument can take the following values:

    • MOVEFILE_REPLACE_EXISTING = 1 Replaces the existing file.

    • MOVEFILE_WRITE_THROUGH = 8 Guarantees that the function will not return control until the file is flushed from the intermediate buffer to the disk.

    • MOVEFILE_COPY_ALLOWED = 2 Specifies that when the new file is placed to another volume, the movement is carried out using two functions: CopyFile and DeleteFile .

    • MOVEFILE_DELAY_UNTIL_REBOOT = 4 Delays the file movement until the system is rebooted. This requires administrative privileges.

  • SetFilePointer This sets the file pointer to an arbitrary position. The first parameter of this function is the descriptor of the opened file. The second parameter is the least significant part (32 bits) of the pointer offset value. The third parameter is the most significant part of the pointer offset. The fourth parameter defines the movement mode and can take the following values:

    • FILE_BEGIN = 0 Counts off the position from the beginning of the file.

    • FILE_CURRENT = 1 Determines the position based on the current position.

    • FILE_END = 2 Determines the pointer position based on the end of the file.

    Note that the movement can be carried out toward both the end of the file and the beginning of the file. Thus, the offset is interpreted as a signed 32-bit number.

  • SetEndOfFile The function moves the end of the file to the current position. The only argument of this function is the file descriptor. The function can truncate the file or increase its length.



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net