Good day,
Here is a summary:
Context
Multiple photos with simple names like 1.jpg must be moved to a folder already containing similar file names
Goal
Renaming all files (*.jpg) from a folder with a random file name.jpg to move them to a folder that may contain simple file names.jpg
Attempts
rename x.jpg %RANDOM%.jpg works with one file name but
rename *.jpg %RANDOM%.jpg tries to rename all files with the same instant value of %random% variable.
Additional features
This may also be good to rename it with something like [date]0001.jpg [date]0002.jpg ...
Thank you four your help, my DOS knowledge is getting greater with all of you!
Renaming all files with random names
Moderator: DosItHelp
Re: Renaming all files with random names
Is this a one-time task?
The shareware Total Commander has a move/copy feature were it can rename the files being copied if they clash with a another filename, or it can rename the target filename. The feature can do an entire folder without prompting.
The shareware Total Commander has a move/copy feature were it can rename the files being copied if they clash with a another filename, or it can rename the target filename. The feature can do an entire folder without prompting.
Re: Renaming all files with random names
To rename&move to random file names:
To rename&move to [date]####.jpg file names:
EDIT: I added setlocal commands that were missed, as foxidrive noted...
Code: Select all
@echo off
setlocal EnableDelayedExpansion
cd sourceDir
for %%f in (*.jpg) do (
call :getNewName
move "%%f" "targetDir\!newName!.jpg"
)
goto :EOF
:getNewName
set newName=%random%
if exist "targetDir\!newName!.jpg" goto getNewName
exit /B
To rename&move to [date]####.jpg file names:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
cd sourceDir
set i=0
for %%f in (*.jpg) do (
set /A i+=1
set newName=000!i!
set newName=[%date%]!newName:~-4!
move "%%f" "targetDir\!newName:/=-!.jpg"
)
EDIT: I added setlocal commands that were missed, as foxidrive noted...
Last edited by Aacini on 10 Mar 2012 19:39, edited 1 time in total.
Re: Renaming all files with random names
Greetings Shawn@Rogers,
Here's a random approach that you can 'try before you buy'.
Have a look at test_me.bat to ensure you're getting your moneys worth
and then move the files.
I prefer Aacini's script which has error checking for the 'move' .
Best wishes!
Here's a random approach that you can 'try before you buy'.

Code: Select all
::Limited Testing
@echo off
setlocal
for /f "delims=" %%a in ('dir *.jpg /b') do call :ren_it "%%a"
goto :eof
:ren_it
set max=999
set min=1
set /a rng=%random% %% (max - min + 1)+ min
echo ren "%~1" "%rng%_%var%.jpg">>test_me.bat
Have a look at test_me.bat to ensure you're getting your moneys worth
and then move the files.
I prefer Aacini's script which has error checking for the 'move' .
Best wishes!
Last edited by Ocalabob on 10 Mar 2012 21:08, edited 1 time in total.
Re: Renaming all files with random names
Re Greetings Shawn@Rogers,
Here's another rename script using the current date. Caveat Emptor!
Again, check the contents of test_me.bat for desired results then
add your 'move' command.
Best wishes!
Here's another rename script using the current date. Caveat Emptor!
Code: Select all
::Limited Testing
@echo off
setlocal
set mydate=%date%
set mynewdate1=%mydate:/=%
set mynewdate2=%mynewdate1:~4,8%
for /f "delims=" %%a in ('dir *.jpg /b') do call :date_it "%%a"
goto :eof
:date_it
echo ren "%~1" "%mynewdate2%_%~1">>test_me.bat
Again, check the contents of test_me.bat for desired results then
add your 'move' command.
Best wishes!
Last edited by Ocalabob on 10 Mar 2012 21:09, edited 1 time in total.
Re: Renaming all files with random names
Aacini wrote:To rename&move to random file names:
To rename&move to [date]####.jpg file names:
issues here Aacini.
delayed expansion isn't declared so they won't work in a standard system, right?
-
- Posts: 7
- Joined: 13 Feb 2012 15:53
Re: Renaming all files with random names
Thank you for your replies!
Unfortunately, my computer has some major problems, so I will not be able to test your solution now, but I will.
Sorry for the delay.
Unfortunately, my computer has some major problems, so I will not be able to test your solution now, but I will.
Sorry for the delay.