RenameFile[file1,file2]
renames file1 to file2.
RenameFile
RenameFile[file1,file2]
renames file1 to file2.
Details and Options
- file1 must already exist; file2 must not.
- RenameFile sets the modification date for file2 to be the same as for file1.
- RenameFile returns the full new file name, or $Failed if the file cannot be renamed.
- RenameFile works on cloud objects, changing their cloud file names but not their UUIDs.
- RenameFile works on local objects.
- Files can be specified either using "path" or File["path"].
- RenameFile has the following option:
-
OverwriteTarget False whether to overwrite if the target file already exists
Examples
open all close allBasic Examples (1)
file = $InstallationDirectory <> "/Documentation/English/System/ExampleData/ocelot.jpg";cfile1 = FileNameJoin[{$TemporaryDirectory, "ocelot.jpg"}];CopyFile[file, cfile1]cfile2 = FileNameJoin[{$TemporaryDirectory, "test123"}];RenameFile[cfile1, cfile2]Import[cfile2]DeleteFile[cfile2]Scope (3)
Rename a file specified by the File object:
file = File[CreateFile[]]newfile = File[FileNameJoin[{$TemporaryDirectory, CreateUUID[]}]];RenameFile[file, newfile]RenameFile works on cloud objects:
obj = CloudPut[12345, "cloudfile"]RenameFile[obj, CloudObject["newfile"]]CloudGet[CloudObject["newfile"]]DeleteObject[CloudObject["newfile"]]Convert an anonymous object to a named one:
obj = CloudPut[N[Pi, 10]]RenameFile[obj, CloudObject["pi.wl"]]CloudGet[CloudObject["pi.wl"]]DeleteObject[CloudObject["pi.wl"]]RenameFile works on local objects:
lo = Put[42, LocalObject[]]RenameFile[lo, LocalObject["some/path"]]Get[%]See Also
CopyFile DeleteFile RenameDirectory File LocalObject CloudObject
Function Repository: FileNameEdit
Tech Notes
Related Guides
Related Workflows
- Name a Notebook in the Cloud
History
Introduced in 1991 (2.0) | Updated in 2014 (10.0) ▪ 2016 (11.0) ▪ 2020 (12.1)
Text
Wolfram Research (1991), RenameFile, Wolfram Language function, https://reference.wolfram.com/language/ref/RenameFile.html (updated 2020).
CMS
Wolfram Language. 1991. "RenameFile." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/RenameFile.html.
APA
Wolfram Language. (1991). RenameFile. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RenameFile.html
BibTeX
@misc{reference.wolfram_2026_renamefile, author="Wolfram Research", title="{RenameFile}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/RenameFile.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_renamefile, organization={Wolfram Research}, title={RenameFile}, year={2020}, url={https://reference.wolfram.com/language/ref/RenameFile.html}, note=[Accessed: 12-June-2026]}