Recursively rename files in subfolders Windows batch file -


I have a large number of files in subfolders under the basic folder named CFile: C: \ Images

< P> All files have the same prefix pattern of the same length, 3 characters, i.e. "[number] [digits] -"

  01-filename.jpg 55-filename .jpg 82-filename .jpg  

How do I strip the prefix with filenames by running a batch file in each subfolder, but I want to turn on a batch files to the original folder Fear and repeat steps through each subfolder and change the alias / name with each filename.

The code below does not work :-( Any help would be great: -)

  for setlocal enabled extension / r "c: \ images \ "%% f in (* .jpg) (Set up push set file name = %% f filename =! Filename: ~ 3! Rename" %% f ""! Filename! "Popped)  < 
 

You must specify a filename that is not included Rename for the second argument :

  @echo for offlocal enabled extension / r "c: \ images \" in %% (* .jpg) (set file name = %% ~ nxf) T fai Name =! Filename: ~ 3! Rename "%% f" "! Filename!")  

%% ~ nxI returns both file names and extensions is.

It may also be a good idea to check that the file is actually required to change its name:

  @echo closed / R "c: \ images \" %% f in (* .jpg) (file name = %% ~ nxf set) "! Filename: ~ 2,1!" == "-" (file name =! Filename: ~ 3! Rename "%% f" "filename!"))  

Finally add a message:

  @echo to set offlocal enabled extension / r "c: \ images \" %% f (* .jpg) (file name = %% ~ nxf set if "! File name: ~ 2,1! "==" - "(file name = set! Filename: ~ 3! Rename echo! %% f to! Filename !! Rename" %% f ""! Filename! ") Else (echo echo file %% F.))  

And for this you do not need pushd and popd .


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -