Monday, May 20, 2024
HomeWindowsBatch file programmingXP Batch Files: Copy images from camera to pc and organize by...

XP Batch Files: Copy images from camera to pc and organize by date

This is a quickie recipe on how to create a batch file that will copy all of your photos/videos from a memory stick or camera onto your pc’s my pictures folder (c:\documents and settings\userid\my documents\my pictures). this batch file will show you how to setup a prompt and using a basic if/then statement.


Well, i like to organize my thousands of digital folders in a date type of hierarchy. i use a year > specific date format. so my “My Pictures” folder looks like this;


then in each year’s folder, i have them named in a MM-DD-YYYY format, ie:

i decided that today i was sick of going in and doing all of my folder creating manually, so i wrote a batch file to do this.

here’s the code (copy and paste into notepad. then save file as a text file. then rename to a .bat extension to make a batch file; ie named test.txt, rename to test.bat):

    @REM Author: seamonkey420 Date: 12/25/06
    @REM This is my custom copy batch file for pictures.
    @REM It will create a new folder w/todays date in the My Pictures folder.
    @REM NOTE! always do a trial run first! you can run the batch file from any folder or path
    @REM No errorchecking is in place, be sure to type in the paths as D: or J: if the camera
    @REM drive is the D or J. case sensitive too. you can add these yourself if you’d like

    @REM Setting the global varibles
    @REM userfolder is basically which drive your my documents folder is located in
    @REM —default should be fine for most people w/normal xp installs
    @REM cameraDrive is the drive for your camera
    @REM type is the type of files your camera saves your images as, most are jpg
    @REM (used to find folder of vids on camera)

    ECHO seamonkeys camera to pc copy script
    ECHO ________________

    SET userfolder=C:
    SET type=jpg
    SET /P cameradrive=Enter Camera Drive Letter (ie D:) and hit Enter:

    @REM Finds what your userid is for user running script and then sets it as a user variable
    for /f “tokens=3 delims=\” %%i in (“%USERPROFILE%”) DO (set user=%%i)

    @REM parses month, day, and year into mm , dd, yyyy formats to create folders off of!

    FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (‘DATE/T’) DO SET mm=%%B
    FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (‘echo %CDATE%’) DO SET dd=%%B
    FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (‘echo %CDATE%’) DO SET yyyy=%%B
    SET date=%mm%%dd%%yyyy%

    @REM Creating a folder in the ‘my pictures’ folder w/the [MM-DD-YYYY] format
    @REM Also changes directory to the new folder
    @REM –I use a year\date hierarchy to sort photos, so for example:
    @REM — [2006]\[12-25-2006]\dsc004.jpg, etc; keeps it easy to find via date

    cd “Documents and Settings\%user%\My Documents\My Pictures”
    mkdir “[%yyyy%]”
    cd “[%yyyy%]
    mkdir “[%mm%-%dd%-%yyyy%]”
    cd “[%mm%-%dd%-%yyyy%]”

    @REM Finds full path of where photos are on the camera
    @REM and also copies them to the new folder (limited to 2 subfolders,
    @REM you’ll need to add a third for statement if your images are nested deeper and change token to 4)

    FOR /F “TOKENS=2 DELIMS=\” %%A IN (‘dir /b /s *.%type%’) DO SET p1=%%A
    FOR /F “TOKENS=3 DELIMS=\” %%A IN (‘dir /b /s *.%type%’) DO SET p2=%%A
    CD “%p1%\%p2%”
    COPY *.* %userfolder%

    @REM Delete the originals prompt and then actions

    SET /P delete=Delete Original Photos from Camera (y/n)?

    IF /I “%delete%”==”y” GOTO delY
    IF /I “%delete%”==”n” GOTO delN

    del /q *.*
    explorer.exe “%userfolder%\Documents and Settings\%user%\My Documents\My Pictures\[%yyyy%]\[%mm%-%dd%-%yyyy%]”

    explorer.exe “%userfolder%\Documents and Settings\%user%\My Documents\My Pictures\[%yyyy%]\[%mm%-%dd%-%yyyy%]

after doing a ton of scripting in AIX and UNIX for my old job, i found that a cleanly written script w/tons of remarks on what functions do will help you down the road and help avoid forgetting what a script or command actually does.

this script will need to be modified if you are not using the default my pictures location on your pc (ie if you moved your my documents folder to a different location, this script will not work as is).

does the following

1. it will prompt you for what drive letter your digital camera or memory stick your copying from is, be sure to use a colan (ie D: )

2a. after doing that, it will go to your my pictures folder, make a folder for the current year in a [yyyy] format (ie [2006] ), then in that folder, create a new folder w/todays date (ie [12-25-2006] ).

2b. also, it will go to your camera/memory stick’s root drive and try to find the folder location where your images are saved (it will only go 2 levels deep, you can add a line to fix this problem if you have a deeper nested folders that your camera uses)

3. it will then copy all files on the camera/memory stick to here.

4. finally, it will ask you if you want to remove the original files from the camera/memory stick and then open up the folder to where the pics just were copied to on your pc.

-if your camera saves files as tiiffs or bmps, change the “SET type=jpg” to tiff or bmp.
-change the ECHO OFF to ECHO ON to see errors or output if your having problems running the script. also add a pause command at the end so you can fully analyze what the script is doing.
-you can run this script from any location and it should parse correctly.
-read my REM in the batch file to explain what sections do/are!

Jimmy S
Jimmy S
Jimmy Selix is an early adopter that loves to be one of the first on the block to have the latest and greatest in technology and gadgets. Another love of his is being able to share his knowledge to others seeking it. Feel free to drop any comments or questions that you may have.


Please enter your comment!
Please enter your name here

Most Popular


Recent Comments

error: Content is protected !!