在MATLAB中重命名文件

4

我想以编程方式将工作目录中的文件从a = 'temp.txt'重命名为b = 'hello.txt'。你建议如何操作?MATLAB中是否有简单的文件重命名函数?

2个回答

7
我认为您要寻找的是MOVEFILE。

是的,那就是我最终做的。 - stanigator

6
以下是几个解决方案列表:
  • Use the MOVEFILE function (as suggested by mtrw).
  • Use the SYSTEM function to execute an operating system command. For example (on Windows):

    system('rename temp.txt hello.txt');
    system(['rename ' a ' ' b]);  % If the file names are stored in strings
    
  • Use the shell escape operator (!) to invoke a system command. For example (on Windows):

    !rename temp.txt hello.txt
    

    If the file names are stored in strings, you would need to use EVAL:

    a = 'temp.txt';
    b = 'hello.txt';
    eval(['!rename ' a ' ' b]);
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接