File and directory operations in Delphi, including ExtractFilePath and ParamStr.

In Delphi, we can use the ExtractFilePath function to extract the file path information and the ParamStr function to retrieve command line arguments. In addition, Delphi also provides other file and directory manipulation functions and procedures as shown below:

  1. ExtractFileName: Extract the name of the file (including the extension).
  2. The variable FileName stores the result of extracting the file name from the file path ‘C:\MyFiles\myfile.txt’.
  3. ExtractFileExt: Extract the file extension.
  4. Extract the file extension from the file path ‘C:\MyFiles\myfile.txt’ and store it in the variable FileExt. // Output: .txt
  5. ExtractFileDir: Retrieve the parent directory of the file.
  6. Output the directory of the file ‘C:\MyFiles\myfile.txt’ as ‘C:\MyFiles’.
  7. Check if the file exists.
  8. If the file ‘myfile.txt’ exists in the ‘C:\MyFiles’ directory, display a message saying “File exists”. Otherwise, display a message saying “File does not exist”.
  9. Check if the directory exists.
  10. if the directory ‘C:\MyFiles’ exists, display the message ‘Directory exists’; otherwise, display the message ‘Directory does not exist’.
  11. CreateDir: Make a directory.
  12. If the directory ‘C:\MyFiles’ does not exist, then create the directory ‘C:\MyFiles’.
  13. DeleteFile: Remove the file.
  14. Remove the file named myfile.txt from the MyFiles folder located in the C drive.
  15. RemoveDir: Delete directory.
  16. Delete the directory ‘C:\MyFiles’.
  17. RenameFiles: Rename files.
  18. Change the name of the file from ‘oldfile.txt’ to ‘newfile.txt’ in the ‘C:\MyFiles’ directory.
  19. FindFirst/FindNext: Search for files in a directory. Patterns can be matched using wildcards.
  20. Declare a variable named SearchRec of type TSearchRec. If the first file found in the directory ‘C:\MyFiles\’ with a .txt extension is successfully found, then repeat the process of handling each file until there are no more files left. Show a message with the name of each file found. Close the search once all files have been processed.

These functions and procedures offer basic functionality for file and directory operations in Delphi. You can choose the appropriate functions to use based on your actual needs.

bannerAds