REM Files and Folders Renamer
REM Renames all files and folders (including sub-folders) giving them certain numbers
REM Example:
REM Before: Docs\FirstDoc.doc, Docs\SecondDoc.doc, Pics\Wife.jpg
REM After: 1\1.doc, 1\2.doc, 2\3.jpg
REM Warning! Do not run this script from the root directory of the disk and from other important folders, because it may cause loss of your data or/and crash of the operating system
@ECHO off
SETLOCAL enabledelayedexpansion
CLS
ECHO All files in the current directory and its sub-directories are to be renamed
ECHO Terminate the script to cancel the action
PAUSE
ECHO Renaming folders
SET num=0
FOR /r %%d in (.) do  ( 
SET folder!num!=%%d
SET /a num+=1
)
SET /a num-=1
IF %num% gtr 9   SET prefix1=0
for /l %%i in (%num%,-1,1) do ren "!folder%%i!" %%i 2> nul
ECHO Renaming files
:files
SET num=0
FOR /f "tokens=*" %%f in ('dir /b /s') do  ( 
IF not %%~nf==%~n0 (  
SET /a num+=1
ECHO %%f
if not "%%~xf"=="" ren "%%f" !num!%%~xf 2> nul
)
)
ECHO Done!
PAUSE
