Skip to content

Modern Fs MoveFile

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

Home › Filesystem › Filesystem Library › MoveFile

MoveFile

Moves or renames a file, even across volumes; refuses an existing destination by default.

Syntax

MoveFile( src, dst [, overwrite ] )

Examples

#import "std/fs"
using fs

'' Everything below happens inside a temp directory of its own, and is
'' removed at the end
dim td as FsResultUStr = CreateTempDir( "fbdoc" )
dim as ustring dir_ = td.Value( )

dim as ustring a = PathJoin( dir_, "a.txt" )
dim as ustring b = PathJoin( dir_, "b.txt" )
WriteAllText( a, "hello" )

print MoveFile( a, b ).IsOk( )           '' true
print Exists( a )                        '' false -- the source is gone
print ReadAllText( b ).Value( )          '' hello

'' Overwrite defaults FALSE here too
WriteAllText( a, "second" )
print MoveFile( a, b ).IsOk( )           '' false
print MoveFile( a, b, true ).IsOk( )     '' true

RemoveDirAll( dir_ )

Library: Filesystem Library
Category: Filesystem
Documented under: File Operations

Clone this wiki locally