Monday, September 12, 2011

To replace the un-necessary strings in filename

Somehow, the filenames had infections with the extra '%E7%E7htm'.
What surprises me is that not all files had the same error.
So, I wrote a simple code to get rid of the extra characters in the filename/ extension.



% To replace   '%E7%E7htm' by 'htm'

% fn = '2Oct_09.%E7%E7htm'
list = dir;

jj = 1;
while jj < length ( list)
    fn = list(jj,1).name;
    [pathstr, name, ext] = fileparts(fn)
    if  strcmp(ext,'.%E7%E7htm') % ~list(jj,1).isdir
        
%         if strcmp(fn(9:15),'%E7%E7h')
          newfn=  strrep(fn, '%E7%E7h', 'h');
%         end
          system([ 'mv ' fn,' ' newfn])
        
%       disp('asdf')  
    end
    jj = jj+1;
end


No comments: