How to move files to one level up and append the name of the folder in which they are contained?
22 次查看(过去 30 天)
显示 更早的评论
Hello,
My folders and files are arranged as follows:
myFolder/0.0001/zNormal.vtp
myFolder/0.0002/zNormal.vtp
myFolder/0.0003/zNormal.vtp
myFolder/0.0004/zNormal.vtp
myFolder/0.0005/zNormal.vtp
myFolder/0.0006/zNormal.vtp
myFolder/0.0007/zNormal.vtp
myFolder/0.0008/zNormal.vtp
myFolder/0.0009/zNormal.vtp
myFolder/0.001/zNormal.vtp
I'd like to move all the 'zNormal.vtp' files to one level up and append the name of the folders in which they are contained.
Example:
myFolder/0.0001/zNormal.vtp --> myFolder/zNormal_0.0001.vtp.
So the 0.0001 folder would now remain empty
Any help would be much appreciated
回答(1 个)
Jan
2021-1-24
BaseFolder = 'myFolder';
FileList = dir(fullfile(BaseFolder, '**', '*.vtp'));
for iFile = 1:numel(FileList)
File = FileList(iFile);
oldFile = fullfile(File.folder, File.name);
newFile = fullfile(BaseFolder, [File.Folder, '_', File.name]);
movefile(oldFile, newFile);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!