file create link ...

Prev Next

Function Names

file create link, file create link all, file create link silently

Description

These functions create symbolic links to existing directories and come in following flavors:
file create link will assert an exception if the link cannot be created (e.g. attempting to create links on files, access restrictions, etc.) Execution will stop immediately.
file create link silently will create the symbolic links 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 create link all tries to create all links and skips the ones which cannot be created. Here, the number of successfully created links will be returned.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled.
Wildcards are not supported here

OS differences

WINDOWS: Following restrictions apply:
1. The link file must end with ".LNK" or ".lnk"
2. Target file: If a different drive is chosen, then the absolute path is required: (OK: D:\directory\filename / Not OK: D:filename, D:directory\filename
3. File names can only be comprised of WIN-1252 characters, i.e. no UNICODE characters allowed.
These restrictions are due to a workaround by creating a small Visual Basic Script (VBS) program which is then executed because this is the only approach to create symbolic links without administrator rights.

Linux / MacOS: Not mandatory to specify ".LNK" at the end, but links can only be created on directories and not on files.

Parameter count

2, 4, etc.

Parameters

No.TypeDescription
1, 3, etc.
input
parameter set or string Symbolic link file name(s)

2, 4, etc.
input
parameter set or string Target file or directory name(s)

Return value

TypeDescription
numeral or string Feedback

file create link: Always "OK", because all errors cause exceptions.
file create link silently: "OK", or short error messages on directories and files.
file create link all: Number of successful operations (links created) is returned.

Exceptions

File is already existing

Examples

      file create link( My Link.lnk, Images  );   // Link to existing directory
      file create link( My Link 2.lnk, Example_Program.b4p ); // Link to filem will work under Windows only

      if (system info[operating system]=Windows)
      {
          system( 'dir /W "My Link*"' ); // Show directory listing
          file delete multiple ( ".", "My Link*.lnk" );
      }
      else // Linux, MacOS
      {
          system( "ls 'My Link'* " ); // Show directory listing
          system( "rm 'My Link'* " ); //
      }

      // Attention: LINUX / MacOS only supports links to directories only, and can only be removed with OS commands.

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 Link 2.lnk   My Link.lnk     
               2 Datei(en),          2’407 Bytes
               0 Verzeichnis(se), 76’158’140’416 Bytes frei
Try it yourself: Open LIB_Function_file_create_link.b4p in B4P_Examples.zip. Decompress before use.

See also

directory create ... Functions