file copy ...

Prev Next

Function Names

file copy, file copy all, file copy silently, file copy overwrite, file copy overwrite all, file copy overwrite silently

Description

These functions make copies of files and come in following flavors:
file copy will assert an exception if the file cannot be renamed (e.g. file not found, file locked, access restrictions, etc.) Execution will stop immediately.
file copy silently will copy the files 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. file copy all tries to copy all files and skips the ones which cannot be renamed. Here, the number of successfully copied files will be returned.
... overwrite ... in the function name will overwrite existing destination files. Without this name ending, attempting to overwrite existing files assert exceptions.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled.

Parameter count

2

Parameters

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

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

2
input
set or string new path and file names

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

Return value

TypeDescription
numeral or string Feedback

file copy / file copy overwrite: Always "OK", because all errors cause exceptions.
file copy ... silently: "OK", or short error messages on directories and files.
file copy ... all: Number of successful operations (files copied) is returned.

Exceptions

File not found
File locked by another application
File not accessible
File is a directory
Number of existing and new path and file names are not equal

Examples

               directory create( My Folder 1, My Folder 2 );

               file copy( {2 : Example_Program.b4p } , { "My Folder 1/Test123.txt", "My Folder 2/Test 456.txt"} );

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

               directory delete recursive( "", "My Folder ?" ); // Delete "My Folder 1" and "... 2".     

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 1

Test123.txt   
               1 Datei(en),            787 Bytes
               0 Verzeichnis(se), 58’232’811’520 Bytes frei
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

Test 456.txt   
               1 Datei(en),            787 Bytes
               0 Verzeichnis(se), 58’232’811’520 Bytes frei
Try it yourself: Open LIB_Function_file_copy.b4p in B4P_Examples.zip. Decompress before use.

See also

file rename ... Functions