directory rename ...

Prev Next

Function Names

directory rename, directory rename all, directory rename silently

Description

These functions rename or move directories and come in following flavors:
directory rename will assert an exception if the directory cannot be renamed or moved (e.g. directory not found, access restrictions, etc.) Execution will stop immediately.
directory rename silently will rename or move the directories until a first failure is encountered. In this case, the applicable one of the short error messages on directories and files will be returned. If no errors have been encountered, "OK" will be returned. directory rename all tries to rename or move all directories and skips the ones which cannot be renamed. Here, the number of successfully renamed or moved directories will be returned.


Moving directories is only possible inside the same disk volume (i.e. same disk drive / desktop computer / server drive)

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled.

Parameter count

2

Parameters

No.TypeDescription
1
input
parameter set or string existing path and directory names

Every parameter must refer to an existing directory. Path name in front is needed if the directory is not located in the working directory.

2
input
parameter set or string new path and directory names

Destination paths and new directory names. The number of existing and new path and directory names must match, otherwise an exception will be asserted.

Return value

TypeDescription
numeral or string Feedback

directory rename: Always "OK", because all errors cause exceptions.
directory rename silently: "OK", or short error messages on directories and files.
directory rename all: Number of successful operations (directories renamed or moved) is returned.

Exceptions

Directory not found
Directory not accessible
Directory is a file
Number of existing and new path and directory names are not equal

Examples

      directory create( My Folder 1, My Folder 2 );
      directory rename( My Folder 1, "My Folder 2\My Folder 3");

      if (system info[operating system]=Windows)
          system( 'dir /W "My Folder 2"' ); // Show directory listing
      else:
          system( "ls 'My Folder 2' " ); // Show directory listing


      directory delete recursive( "", "My Folder *" );

Output

 Datenträger in Laufwerk C: ist Windows
Volumeseriennummer: 96E3-BA76

Verzeichnis von C:\Users\zur-b\OneDrive\Documents\Programme\Beyond4P\B4P_Docu_Maker\My Folder 2

[.]           [..]          [My Folder 3]
               0 Datei(en),              0 Bytes
               3 Verzeichnis(se), 76’150’620’160 Bytes frei
Try it yourself: Open LIB_Function_directory_rename.b4p in B4P_Examples.zip. Decompress before use.

See also

file rename ... Functions