Skip to content

Modern Fs CreateHardLink

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Filesystem › Filesystem Library › CreateHardLink

CreateHardLink

Gives an existing file a second name on the same volume.

Syntax

CreateHardLink( target, lnk )

Notes

  • FsResultBool

Examples

#import "std/fs"
using fs

dim td as FsResultUStr = CreateTempDir( "fbdoc" )
dim as ustring dir_ = td.Value( )
dim as ustring p = PathJoin( dir_, "f.txt" )
WriteAllText( p, "hello" )

dim as ustring lnk = PathJoin( dir_, "same.txt" )
dim r as FsResultBool = CreateHardLink( p, lnk )

if r.IsOk( ) then
    '' A second NAME for one file, not a copy and not a link object
    print ReadAllText( lnk ).Value( )        '' hello
    print IsLink( lnk )                      '' false -- it is not a symlink
    print LinkCount( p ).Value( )            '' 2
else
    print "not supported here: " & r.Failure( ).Message( )
end if

'' Both names must be on the SAME VOLUME, and neither is "the original"

RemoveDirAll( dir_ )

Library: Filesystem Library
Category: Filesystem
Documented under: Links And Permissions

Clone this wiki locally