How to move files to one level up and append the name of the folder in which they are contained?
10 views (last 30 days)
Show older comments
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
Answers (1)
Jan
on 24 Jan 2021
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!