Renaming multilple .txt files
이전 댓글 표시
Hello all,
I have been trying to rename multiple text files with different methods I found around but could not make it work. My files are name as such:
"Z_X12_ABC_000cm_1.txt" ;
"Z_X12_ABC_000cm_2.txt" ;
"Z_X12_ABC_000cm_3.txt" ;
Then,
"Z_X12_ABC_005cm_1.txt"
...
So I have 13 depths and a triplicate for each depth. Which gives me 39 files. In the folder, thanks to my labeling, they are all correctly ordered in alphabetical order.
I would simply would like to rename those 39 files as:
"Z_X12_ABC_1.txt" ;
"Z_X12_ABC_2.txt" ;
"Z_X12_ABC_4.txt" ;
"Z_X12_ABC_5.txt" ;
...
Any help would be appreciated.
댓글 수: 2
dpb
2017년 7월 28일
If you do that as shown you'll destroy the sort order as
n =
'Z_X12_ABC_1.txt'
'Z_X12_ABC_2.txt'
'Z_X12_ABC_4.txt'
'Z_X12_ABC_5.txt'
'Z_X12_ABC_11.txt'
>> sort(n)
ans =
'Z_X12_ABC_1.txt'
'Z_X12_ABC_11.txt'
'Z_X12_ABC_2.txt'
'Z_X12_ABC_4.txt'
'Z_X12_ABC_5.txt'
>>
so you'll not have a 1:1 consonance of the name with the content. Why break a good scheme--what can you accomplish with the other naming scheme can't do as is? I could see eliminating the 'cm' and perhaps shortening the 3-digit field to two for a little brevity, but don't understand why would want to do what you've asked for, exactly; seems like disadvantages would outweigh any possible advantage.
Alex M.
2017년 7월 31일
채택된 답변
추가 답변 (1개)
Vipresh Gangwal
2017년 7월 28일
try using the dir function with an output argument.
myFiles = dir
% sort myFiles structure if you need to
for i = 1:length(myFiles)
% current file = myFile(i);
% rename current file
end
Make sure to ignore the folders "." and ".."
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!