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