Search code examples
batch-filewindows-7cameracopymulti-user

creating a batch file to copy pictures to a network drive


How do I create a batch file that will copy files from a camera to a directory that is prompted from the command line?

example folder structure: {shared drive start folder} <year> <month> <(prompt user for name)> [delete pictures after copied]

I am looking to get this to work to copy pictures from various cameras to one shared folder and have it all sorted by year then month and finally by the user prompted name. I know very little command line commands, all the switches and %'s.. i get lost pretty quickly.

Windows 7 computers and most likely SD cards in readers because most of the cameras don't show up with drive letters (this is part of my problem)

The code:
Show errors:
        ECHO ON

type of file:
        SET type=jpg

to set where the files are going:
        NET USE M:\public\am_class\

to get user input i would use "SET /P" so i would do: 
        SET /P SDdrive=Enter Sd Card drive letter:

Get month and year(and day in case its needed later) to create initial folders:
        FOR /F "TOKENS=1* DELIMS= "%%A IN ('DATE/T') DO SET CDATE=%%B
        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%

change dir to the correct location... this im not sure about but the "NET USE" gives me a direction  to look in (figured out and placed correct code):
        cd\
        cd /DM:\public\am_class\"

make new folders in above main folder
        mkdir "%yyyy%"
        cd "%yyyy%"
        mkdir "%mm%"
        cd "%mm%"

!!next question is this correct to get it to create a folder from the user prompted info? (This is corrected and correct)
        SET /P foldername=Please enter assignment number and press enter:
        mkdir "%foldername%"
        cd "%foldername%"

Go to SDdrive:
        %SDdrive%

Find the Path of the files:
        FOR /F "TOKENS=2 DELIMS\" %%A IN ('dir /b /s *.%type%') DO SET p1= %%A

Change folder and copy to "foldername" folder
        CD"%p1%"
        COPY *.* %foldername%       

Delete the SDcard pics after complete:
        Set /P delete=Delete SD card pictures (y/n)?
        IF /I "%delete%"=="y" GOTO delY
        IF /I "%delete%"=="y" GOTO delN
        :delY
        %SDdrive%
        del /q *.*
        explorer.exe \\landis.xxx\public\am_class\%foldername%\    
        :delN
        explorer.exe \\landis.xxx\public\am_class\%foldername%\ 

Pause for testing only (will be removed in final version):
        Pause

I hope that helps some.


Solution

  • Use the net use command to map the windows share to a drive like X:\ and then use

    xcopy with some appropriate arguments to copy the files.