I am trying to rename over a thousand files of varying length. For example, my original file names are:
1-1.txt
1-13.txt
12-256.txt
...
I would like these files to appear as follows:
100000-1-1.txt
100000-1-13.txt
100000-12-256.txt
...
I have been trying to use the following script:
d = 'directoryname';
names = dir(d);
names = {names(~[names.isdir]).name};
len = cellfun('length',names);
mLen = max(len);
idx = len < mLen;
len = len(idx);
names = names(idx);
for n = 1:numel(names)
oldname = [d names{n}];
newname = sprintf('%s%100000-*s',d,mLen, names{n});
dos(['rename','oldname', 'newname']); % (1)
end
What am I doing wrong? Thanks in advance for your help!!
See if this works for you -
Edit