Quantcast
Channel: How to rename 80.000 files at once in Windows - Super User
Viewing all articles
Browse latest Browse all 10

Answer by kokbira for How to rename 80.000 files at once in Windows

$
0
0

I have 2 solutions:

  1. All files are in the same folder

    • run the following from command prompt on that folder:

      for /f "delims=¯" %i in ('dir /b /on') do ren "%i""._%i"
  2. complete solution when there are files in subfolders AND when you wanna to replace the "n" first characters with a string you want :D

    • create a batch file with the following command
    • change variable parameters to what you want
      • path: put inside "" the root path of your files (e.g. "C:\documents and settings\user\desktop\new folder"
      • numfirstchars2replace: put a number with the first characters to replace (in your case, 2)
      • str2put: put a string to be added as a prefix of the new filename (in your case, ._)
    • run it in a folder different from where the files are


@echo off::only to tell user what this bat are doingecho.1.initializing...::enable that thing to allow, for example, incremental counter in a for loop :)echo.- EnableDelayedExpansionSETLOCAL EnableDelayedExpansion::variablesecho.- variables:: - place here the absolute root path of your filesset path="put here where are the root folder of your files"set pathbak=%cd%set numfirstchars2replace=2set str2put=._::go to %path% and its driveletterecho.- entering the path you wantfor /f "delims=¯" %%i in ('echo.%path%') do %%~dicd %path%::search all subfolders and save them to a temp fileecho.- searching for subfoldersecho.%path%>%temp%\tmpvar.txtfor /f "delims=¯" %%i in ('dir /s /b /on /ad') do echo."%%i">>%temp%\tmpvar.txt::execute command for root folder and all found subfoldersecho.echo.2.executing...for /f "delims=¯" %%i in (%temp%\tmpvar.txt) do (  cd %%i  echo.- in folder: %%i  for /f "delims=¯" %%j in ('dir /b /on /a-d') do (    set newname=%%j    set newname=!newname:~%numfirstchars2replace%,1000!    echo.- renaming from "%%j" to "%str2put%!newname!"...    ren "%%j""%str2put%!newname!"  ))echo.echo.3.exiting...::return to %pathbak% and its driveletterfor /f "delims=¯" %%i in ('echo.%pathbak%') do %%~dicd %pathbak%@echo on

Viewing all articles
Browse latest Browse all 10

Trending Articles