Batch photo organizer

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
namenick
Posts: 8
Joined: 06 May 2015 09:34

Batch photo organizer

#1 Post by namenick » 06 May 2015 10:00

Hi there,
First of all excuse me: I'my from Italy and my English is bad :cry:
I started using bat flies a few ago and now I want to create a bat file wich can reorganize my photo.
This is my idea:
1) extract all the image from the sub folders they are and move them in a single folder.
2)rename the photo using the exif information
3)sort the images just renamed in appositely created roller and ma ed with the date of the photo shot.
Can you help me? Is it possibile? I know that there are some programs that do this but i would not like to use them.
Thank you.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch photo organizer

#2 Post by foxidrive » 06 May 2015 20:55

namenick wrote:Hi there,
First of all excuse me: I'my from Italy and my English is bad :cry:


Welcome to the forum.
English is a terrible language anyway - it's so difficult to follow all the irrational ways words are used, and that's even for someone that has English as their native tongue!

1) extract all the image from the sub folders they are and move them in a single folder.

This is easy if all the names are all unique.

2)rename the photo using the exif information

This can be done with a free third-party command line tool.

3)sort the images just renamed in appositely created roller and ma ed with the date of the photo shot.

The images can be sorted into folders by their date - say 2014-01 for January 2014 if that is what you mean.

namenick
Posts: 8
Joined: 06 May 2015 09:34

Re: Batch photo organizer

#3 Post by namenick » 07 May 2015 09:35

foxidrive wrote:
namenick wrote:Hi there,
First of all excuse me: I'my from Italy and my English is bad :cry:


Welcome to the forum.
English is a terrible language anyway - it's so difficult to follow all the irrational ways words are used, and that's even for someone that has English as their native tongue!

1) extract all the image from the sub folders they are and move them in a single folder.

This is easy if all the names are all unique.

2)rename the photo using the exif information

This can be done with a free third-party command line tool.

3)sort the images just renamed in appositely created roller and ma ed with the date of the photo shot.

The images can be sorted into folders by their date - say 2014-01 for January 2014 if that is what you mean.



You understood everything perfectly.
I just found a way to do the first part.
Can You tell me whats the tool for the second part and how can I use it in my batch file?
I aslo would like to know how to do the third step, wich command should I use? How?
Thank you so much for your fast reply,

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch photo organizer

#4 Post by foxidrive » 08 May 2015 06:50

I may have been swift to reply but I haven't been back until now.

There is a free exifread tool here and it has simple command line options
http://www.takenet.or.jp/~ryuuji/miniso ... d/english/

and I can't recommend any tool because I don't routinely use EXIF manipulations.

To give you a script to handle your files, and also to sort them later, you would have to supply the EXIF output from an image - and also tell us if all the images have the expected exif data, or if they are from different sources and could have anything inside them.

For the step 2) above I meant that the exif tool provides the information and a batch script can use that to rename it - and also for the sorting step.

You might find a better EXIF tool to read the data from the command line - but look at the command line options in the exifread tool and see what information it provides. Test it in a folder with copies of a few of your files first.

I also have ExifTool by Phil Harvey here and it looks very capable. You can google it to see.

namenick
Posts: 8
Joined: 06 May 2015 09:34

Re: Batch photo organizer

#5 Post by namenick » 10 May 2015 09:48

:D Hi again,
I'm going a bit mad...
I downloaded the tool you suggested me and I found the way to do this from batch: open a file with it and making it write a log.
Inside the log there are a lot of info and i don't know how to extract the right one.
i know i'm a noob and most of my problems are due to my poor know about dos.
Anyway I have a plan.
Here's the plan.
For every file:
Open it with the exiftool.
Create the log.
Extract the right info and set a variable to this info.
rename the same file in variable(just created).jpg
move it to a temporary folder
delete the log file
repeat

now maybe i'm wrong asking you for this kind of help but, can you write me the base script for this actions?
Some info: the log are named like the original files they are about. The date, wich is the info i need is placed in a document like this I paste here.
Hope i'm don't disturb you too much. thanks.



Filename : P.jpg
JFIF_APP1 : Exif
JFIF_APP14 : Photoshop 3.0
JFIF_APP1 : http
JFIF_APP2 : ICC Profile (offset:28393 size:3151bytes)
JFIF_APP15 : Adobe
AdobeResource
IPTC-NAA : 20Byte
Unknown (1061) : 16Byte
DisplayInfo : 16Byte
Unknown (1062) : 14Byte
GlobalAngle : 4Byte
Global Altitude : 4Byte
PrintFlags : 10Byte
Print flags : 10Byte
Color halftoning information : 72Byte
Color transfer functions : 112Byte
Grid and Guides information : 16Byte
URL List : 4Byte
Slices : 838Byte
Unknown (1064) : 12Byte
Document specific IDs : 4Byte
ThumbnailResource : JPEG Format (Offset:10813Size:8616)
Thumbnail Type : JPEG
Thumnail Width : 160
Thumbnail Height : 102
Version Info : 124Byte
JPEG quality : 00010100
IPTC
Record version : 16B4
Taking a picture day : 20120405
Main Information
Make : NIKON
Model : COOLPIX P7000
Orientation : left-hand side
XResolution : 2400000/10000
YResolution : 2400000/10000
ResolutionUnit : Inch
Software : Adobe Photoshop Elements 10.0 Windows
DateTime : 2012:04:05 23:00:16
ExifInfoOffset : 216
Sub Information
ExposureTime : 1/80Sec
FNumber : F5,6
ExposureProgram : Manual
ISOSpeedRatings : 100
ExifVersion : 0221
DateTimeOriginal : 2012:04:05 13:16:40
DateTimeDigitized : 2012:04:05 13:16:40
ShutterSpeedValue : 1/80Sec
ApertureValue : F5,6
ExposureBiasValue : EV0,0
MaxApertureValue : F2,8
MeteringMode : Division
LightSource : Unidentified
Flash : Not fired(Compulsory)
FocalLength : 16,30(mm)
ColorSpace : sRGB
ExifImageWidth : 3261
ExifImageHeight : 2086
SensingMethod : OneChipColorArea sensor
FileSource : DSC
SceneType : A directly photographed image
CustomRendered : Normal process
ExposureMode : Manual
WhiteBalance : Auto
DigitalZoomRatio : 0/100
FocalLength(35mm) : 76(mm)
SceneCaptureType : Standard
GainControl : None
Contrast : Normal
Saturation : Normal
Sharpness : Hard
SubjectDistanceRange : Unknown
Thumbnail Information
Compression : OLDJPEG
XResolution : 72/1
YResolution : 72/1
ResolutionUnit : Inch
JPEGInterchangeFormat : 806
JPEGInterchangeFormatLength : 8587

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch photo organizer

#6 Post by foxidrive » 10 May 2015 23:44

This is untested - Put the batch file and some copies of your images into a test folder and try it.

You need to put the exif program command where it says in the batch file.

If it fails then:
1) show us the error message, and check that the file that is created by the exif program for an image named "SD000019.JPG" is SD000019 with no extension, for example.
2) Also tell us the command line you use to create the file.

It would be helpful to paste your working batch file in a reply so other people in the future can use it.

Code: Select all

@echo off
for %%z in (*.jpg) do (

  place exif command here using "%%z" where the filename goes - including the double quotes

      for /f "tokens=1-7 delims=: " %%a in (' type "%%~nz" ^| find "DateTimeOriginal :" ') do (
         md "%%b-%%c" 2>nul
         move "%%z" "%%b-%%c"
         ren "%%b-%%c\%%z" "%%b-%%c-%%d_%%e-%%f-%%g%%~xz"
         if exist "%%~nz" del "%%~nz"
      )
)
pause

namenick
Posts: 8
Joined: 06 May 2015 09:34

Re: Batch photo organizer

#7 Post by namenick » 11 May 2015 10:17

:( it doesen't work
Here's the batch file I made.

Code: Select all

@echo off
for "%%z" in (*.jpg) do ("C:\Users\Simon\Desktop\ExifRead.exe" -TEXT C:\Users\Simon\Desktop\OutputImmagini\"%%z")
for /f "tokens=1-7 delims=: " %%a in (' type "%%~nz" ^| find "DateTimeOriginal :" ') do (md "%%b-%%c" 2>nul move "%%z" "%%b-%%c"  ren "%%b-%%c\%%z" "%%b-%%c-%%d_%%e-%%f-%%g%%~xz"if exist "%%~nz" del "%%~nz")
pause


It simply closes and it doesen't do anything. I tried puttinf pause after the first string but it doesen't do anything.
I suppose that the Text command doesen't allows %%a or other variables.
I thought that this could be solved renaming previously all the photos in 1.jpg, 2.jpg... and renaming with them with the date once a time using another varibale wich gets +1 every time a file is renamed with the date
I don't know anything else. Thank you so much for your help.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch photo organizer

#8 Post by foxidrive » 11 May 2015 23:51

You batch file is missing end-of-lines and running different commands on a single line.

Copy and paste the code I have shown above and add the command where it says to.

namenick
Posts: 8
Joined: 06 May 2015 09:34

Re: Batch photo organizer

#9 Post by namenick » 12 May 2015 07:39

You are right excuse me.
here's what I did now

Code: Select all

@echo off
for %%z in (*.jpg) do (

  start ExifRead.exe -TEXT "%%z"

      for /f "tokens=1-7 delims=: " %%a in (' type "%%~nz" ^| find "DateTimeOriginal :" ') do (
         md "%%b-%%c" 2>nul
         move "%%z" "%%b-%%c"
         ren "%%b-%%c\%%z" "%%b-%%c-%%d_%%e-%%f-%%g%%~xz"
         if exist "%%~nz" del "%%~nz"
      )
)
pause


It says n time (n=number of files) Impposible to find the specified file.
I really don't know what to do.

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Batch photo organizer

#10 Post by Ben Mar » 12 May 2015 15:08

Namenick, give this a try:

Code: Select all

@echo off
for %%z in (*.jpg) do (

   exifread.exe -text "%%z"

   for /f "tokens=1-7 delims=: " %%a in (' type "%%~nz.txt" ^| find "DateTimeOriginal :" ') do (
      if not exist "%%b-%%c-%%d" md "%%b-%%c-%%d" 2>nul
      move "%%z" "%%b-%%c-%%d\%%b-%%c-%%d_%%e-%%f-%%g%%~xz"
      del "%%~nz.txt"
   )
)

namenick
Posts: 8
Joined: 06 May 2015 09:34

Re: Batch photo organizer

#11 Post by namenick » 13 May 2015 02:07

Today I'm out until 24:00 probably i will try tomorrow

namenick
Posts: 8
Joined: 06 May 2015 09:34

Re: Batch photo organizer

#12 Post by namenick » 14 May 2015 14:50

Hey it works! but when i try to put everything toghether it fails.
Here's the file I made with your help

Code: Select all

pushd "C:\Users\nnnnn\Desktop\Input"
for /r %%f in (*.jpg) do (COPY "%%f" "C:\Users\Simone\Desktop\Output")
CLS
@PAUSE

@echo off
for %%z in (*.jpg) do (

   ExifRead.exe -TEXT "%%z"

   for /f "tokens=1-7 delims=: " %%a in (' type "%%~nz.txt" ^| find "DateTimeOriginal :" ') do (
      if not exist "%%b-%%c-%%d" md "%%b-%%c-%%d" 2>nul
      move "%%z" "%%b-%%c-%%d\%%b-%%c-%%d_%%e-%%f-%%g%%~xz"
      del "%%~nz.txt"
   )
)
if exist "C:\Users\nnnnn\Desktop\Output\*.txt" DEL "C:\Users\nnnnn\Desktop\Output\*.txt"
PAUSE


It does't recognise th program code: it says EXIF READ IS NOT RECOGNIZED AS ANINTERNAL OREXTERNAL COMMAND. Any tips?

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Batch photo organizer

#13 Post by Ben Mar » 14 May 2015 15:12

When you use "pushd" you need to call "popd" to return back to your starting point.
So try this:

Code: Select all

pushd "C:\Users\nnnnn\Desktop\Input"
for /r %%f in (*.jpg) do (COPY "%%f" "C:\Users\Simone\Desktop\Output")
popd
CLS
@PAUSE

@echo off
for %%z in (*.jpg) do (

   ExifRead.exe -TEXT "%%z"

   for /f "tokens=1-7 delims=: " %%a in (' type "%%~nz.txt" ^| find "DateTimeOriginal :" ') do (
      if not exist "%%b-%%c-%%d" md "%%b-%%c-%%d" 2>nul
      move "%%z" "%%b-%%c-%%d\%%b-%%c-%%d_%%e-%%f-%%g%%~xz"
      del "%%~nz.txt"
   )
)
if exist "C:\Users\nnnnn\Desktop\Output\*.txt" DEL "C:\Users\nnnnn\Desktop\Output\*.txt"
PAUSE

namenick
Posts: 8
Joined: 06 May 2015 09:34

Re: Batch photo organizer

#14 Post by namenick » 15 May 2015 10:05

Hey it works!
I tried it with a copy of my photo library and the only problem i noticed is that it seems stuck for a lot of time while it's writing the text files.
I think that it could be faster selecting only 100 more or less files and do the operations and then select other 100 files
The other thing i would like to is to give it a sort of interface with button. it could be very useful for some friends of mine to have a Windows stile interface to start the different batch file (i have other files i Would like to give them)
thanks

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Batch photo organizer

#15 Post by Ben Mar » 15 May 2015 12:00

This batch file will process 50 files at a time and pause for 5 seconds then resume to do for the next 50 files, etc. You could modify it to adjust the number of files as well as the delay value in second to your liking.

Code: Select all

pushd "C:\Users\nnnnn\Desktop\Input"
for /r %%f in (*.jpg) do (COPY "%%f" "C:\Users\Simone\Desktop\Output")
popd
CLS
@PAUSE

@echo off
setlocal EnableDelayedExpansion
set count=0
for %%z in (*.jpg) do (
   set /a count+=1
   set /a limit=!count! %% 50
   if "!limit!" == "0" timeout /t 5

   ExifRead.exe -TEXT "%%z"

   for /f "tokens=1-7 delims=: " %%a in (' type "%%~nz.txt" ^| find "DateTimeOriginal :" ') do (
      if not exist "%%b-%%c-%%d" md "%%b-%%c-%%d" 2>nul
      move "%%z" "%%b-%%c-%%d\%%b-%%c-%%d_%%e-%%f-%%g%%~xz"
      del "%%~nz.txt"
   )
)
if exist "C:\Users\nnnnn\Desktop\Output\*.txt" DEL "C:\Users\nnnnn\Desktop\Output\*.txt"
PAUSE


For the button interface it goes beyond the scope of the batch file. You need to use a 3rd party to do the GUI part then use it to call the batch that you have.

Post Reply