在 Tcl 中重命名文件
Rename a file in Tcl
来自 documentation 不清楚该怎么做?
file rename ?-force? ?- -? source target
file rename ?-force? ?- -? source ?source ...? targetDir
The first form takes the file or directory specified by pathname
source and renames it to target, moving the file if the pathname
target specifies a name in a different directory.
我在函数声明中没有看到名为 pathname 的变量。
给定一个 path/to/file.csv
如何将其重命名为 path/to/renamedfile.csv
?
set oldName foobar.txt
set newName bar.txt
file rename $oldName $newName
因权限被拒绝而失败,我想这与 C:
中的文件有关如何做到这一点?
I don't see variable called pathname in function declaration.
您对文档的解释有误。 Pathname是函数声明中source和target参数的说明。
The first form takes the file or directory specified by (pathname)
source and renames it to (pathname) target...
您将 foobar.txt
重命名为 bar.txt
的代码是正确的。在 C:
下直接创建和重命名文件需要管理员权限。您可以通过打开 shell (tclsh) 或具有管理员权限的程序来获取它,例如右击图标 select "Run as administrator".
来自 documentation 不清楚该怎么做?
file rename ?-force? ?- -? source target
file rename ?-force? ?- -? source ?source ...? targetDir
The first form takes the file or directory specified by pathname source and renames it to target, moving the file if the pathname target specifies a name in a different directory.
我在函数声明中没有看到名为 pathname 的变量。
给定一个 path/to/file.csv
如何将其重命名为 path/to/renamedfile.csv
?
set oldName foobar.txt
set newName bar.txt
file rename $oldName $newName
因权限被拒绝而失败,我想这与 C:
中的文件有关如何做到这一点?
I don't see variable called pathname in function declaration.
您对文档的解释有误。 Pathname是函数声明中source和target参数的说明。
The first form takes the file or directory specified by (pathname) source and renames it to (pathname) target...
您将 foobar.txt
重命名为 bar.txt
的代码是正确的。在 C:
下直接创建和重命名文件需要管理员权限。您可以通过打开 shell (tclsh) 或具有管理员权限的程序来获取它,例如右击图标 select "Run as administrator".