Change size of an existing file (on some platforms sparse files are used) or move file to other name and/or location.
file.resize(path, size)
file.move(from, to)
file path (on windows it uses a 'windows' backslash path!)
new filesize in bytes as double
old file path
new file path
logical scalar repesenting the success of this operation
file.resize
can enlarge or shrink the file. When enlarged, the file
is filled up with zeros. Some platform implementations feature
sparse files, so that this operation is very fast. We have tested:
Ubuntu Linux 8, i386
FreeBSD 7, i386
Gentoo Linux Virtual-Server, i386
Gentoo Linux, x86_64
Windows XP
The following work but do not support sparse files
Mac OS X 10.5, i386
Mac OS X 10.4, PPC
file.move
tries to file.rename
,
if this fails (e.g. across file systems) the file is copied to the new location and the old file is removed,
see file.copy
and file.remove
.
# NOT RUN {
x <- tempfile()
newsize <- 23 # resize and size to 23 bytes.
file.resize(x, newsize)
file.info(x)$size == newsize
# }
# NOT RUN {
newsize <- 8*(2^30) # create new file and size to 8 GB.
file.resize(x, newsize)
file.info(x)$size == newsize
# }
# NOT RUN {
y <- tempfile()
file.move(x,y)
file.remove(y)
# }
Run the code above in your browser using DataLab