guides:programming:programmers_reference_manual:renamefile_method_filesystem

RENAMEFILE method (Filesystem)

Renames a specified file, optionally showing a progress information and allowing an Undo operation.

SuccessFlag = Exec_Method( "FILESYSTEM",     
                           "RENAMEFILE",     
                           FileFrom,         
                           FileTo,           
                           RenameFileOptions )
NameRequiredDescription
FileFromYesFully qualified path containing the file to rename (wildcard characters are not allowed).
FileToYesFully qualified path containing the file to rename.
RenameFileOptionsNoContains an @Fm-delimited dynamic array of options that control the behavior of the rename operation:

<1> Allow undo
<2> Allow UI
<3> Parent window ID
<4> Progress dialog title
<5> Allow confirmations

TRUE$ if the rename was performed successfully, or FALSE$ if an error occurred. If the case of the latter event the FILEOPRESULT property may be used to obtain more details regarding the failure.

The RenameFileOptions argument is composed of five fields which control the behavior of the move operation – each field is described fully below:

FieldNameDescription
<1>Allow undoIf TRUE$ then save Undo information. Defaults to FALSE$.
<2>Allow UIIf TRUE$ then allow any appropriate dialogs to be displayed such as progress and error information. Defaults to FALSE$.
<3>Parent window IDSpecifies the name of a WINDOW object to use as the parent for any dialogs displayed during the rename operation.
<4>Progress dialog titleText to display in the progress dialog during the rename operation.
<5>Allow confirmationsIf TRUE$ then allow the user to respond to any confirmation dialogs presented during the rename operation. Defaults to FALSE$.

You cannot rename multiple files with a single call to this method. Use the MOVEFILES method instead.

The RENAMEFILE method is basically a wrapper around the SHFileOperation Windows API function, so it is worth examining at the documentation for this on the MSDN website to get a better idea of the capabilities of this method.

You should use fully qualified path names with this method. Using it with relative path names is not thread safe.

Equated constants for use with the RENAMEFILE method can be found in the PS_FILESYSTEM_EQUATES insert record.

 
// Use the FILESYSTEM RENAMEFILE method rename a file, showing any

   // progress information, and allowing the user to override any

   // conflicts.

   

   $Insert PS_FileSystem_Equates

   $Insert Logical

   

   FileFrom = "c:\my_data\aug_2017\book1.xls"

   FileTo   = "c:\my_data\aug_2017\book1_backup.xls"

   

   RenameOptions = ""  

   RenameOptions<PS_RNF_ALLOWUNDO$>     = TRUE$  ; // Save Undo info

   RenameOptions<PS_RNF_ALLOWUI$>       = TRUE$  ; // Show dialogs

   RenameOptions<PS_RNF_PARENTWINDOW$>  = @Window

   RenameOptions<PS_RNF_PROGRESSTITLE$> = "Renaming book1.xls"

   RenameOptions<PS_RNF_ALLOWCONFIRM$>  = FALSE$

   

   If Exec_Method( "FILESYSTEM", "RENAMEFILE", FileFrom, FileTo, RenameOptions ) Then

      // Renamed OK

   End Else

      ErrorInfo = Get_Property( "FILESYSTEM", "FILEOPRESULT" )

      

      ErrorCode = ErrorInfo<PS_FOR_ERRORCODE$>

      ErrorText = ErrorInfo<PS_FOR_ERRORTEXT$>

   End
 
 
 

MOVEFILES method, FILEOPRESULT property.

  • guides/programming/programmers_reference_manual/renamefile_method_filesystem.txt
  • Last modified: 2023/10/25 10:50
  • by 127.0.0.1