Change the folder names from one digit to 2 digit numbers
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Butterflyfish
il 26 Apr 2016
Commentato: Butterflyfish
il 27 Apr 2016
I have a folder 'data' full of folders which are named like this:
E:\data\foldername1\
E:\data\foldername2\
E:\data\foldername3\
...
E:\data\foldername100\
E:\data\foldername11\
...
I would like to rename the folders with one digit (foldername1- foldername9) with two digits, like that:
E:\data\foldername01\
E:\data\foldername02\
...
As I have lots of those 'data' folders I would like to automate it. I tried without success so far... Could anyone please help me?
2 Commenti
Azzi Abdelmalek
il 26 Apr 2016
If you rename E:\data\foldername1\ to E:\data\foldername10\, then what about the existing E:\data\foldername10\?
Risposta accettata
Alessandro Masullo
il 26 Apr 2016
You can use dir, sscanf, sprintf and movefile.
Use dir to get the list of the folders.
Use scanf to get the number of the folder:
sscanf('folder39','folder%d')
ans =
39
Use sprintf to write the new folder name
sprintf('foldername%04d',15)
ans =
foldername0015
Use movefile to rename your folder.
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!