Renaming multilple .txt files
Afficher commentaires plus anciens
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 commentaires
dpb
le 28 Juil 2017
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.
le 31 Juil 2017
Réponse acceptée
Plus de réponses (1)
Vipresh Gangwal
le 28 Juil 2017
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 ".."
1 commentaire
Alex M.
le 31 Juil 2017
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!