LFNFOR On & FOR %i IN (set) DO command [command parameters]For brevity, we omit 'LFNFOR On' in the next examples.
D:\test>FOR %i IN (file*.txt) DO REN %i prefix_%i [ENTER]The result is that e.g. file1.txt is renamed to prefix_file1.txt.
D:\test>FOR %i IN (file*.*) DO REN %i prefix_%i [ENTER]also renames file2.dat to prefix_file2.dat
D:\test>FOR %i IN (*.txt) DO REN %i prefix_%i [ENTER]makes the 'REN' bug visible. In case of our three original files with filenames 'file1.txt', 'file2.txt' and 'file3.txt', the result will be:
D:\test>FOR %i IN (*.txt) DO REN %i prefix_%i.tmp & REN *.txt.tmp *. [ENTER]What does it do? 'file1.txt' will be renamed to 'prefix_file1.txt.tmp', 'file2.txt' to 'prefix_file2.txt.tmp' etc. The command 'REN *.txt.tmp *.' renames all extensions '.txt.tmp' back to '.txt'.
D:\test>REN *.txt ?????_suffix.txt.tmp & REN *.txt.tmp *. [ENTER]The number of ? equals the maximum number of characters of the original filename. So, 'file1.txt' will be renamed into 'file1_suffix.txt'.
D:\test>REN *.txt ?????????_suffix.txt.tmp & REN *.txt.tmp *. [ENTER]So, 'file1.txt' will be renamed into 'file1_suffix.txt', 'file222.txt' into 'file222_suffix.txt' and 'file33333.txt' into 'file33333_suffix.txt'.
D:\test>REN *.txt F?L*.txt [ENTER]So 'file1.txt' will be renamed in 'FiLe1.txt' and 'temp.txt' into 'FeLmp.txt'.