Link to home
Start Free TrialLog in
Avatar of doc_jay
doc_jay

asked on

copy files from multiple DVD Drives

Need some help writing a script to automate a copy process.

I've got several hundred DVDs that I need to get the info off of them and back 'online' from a jukebox.  The only way is to put the disc in by hand into a DVD reader and then copy the files into a directory, after that I can easily deal with the data.  I have built a machine with 4 DVD drives and I can load a disc into each one.

I need help with writing a script that would read each drive (hopefully at the same time to save time) and then copy ALL of the files off them into the same 'hold' directory.
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Well you can copy multiple at the same time with something like this:

@echo off
set destdir="X:\destpath"
START "D DRIVE" "%Comspec%" xcopy D:\whatever.exe %destdir%
START "E DRIVE" "%Comspec%" xcopy E:\whatever.exe %destdir%
START "F DRIVE" "%Comspec%" "xcopy F:\whatever.exe %destdir%
START "G DRIVE" "%Comspec%" xcopy G:\whatever.exe %destdir%
echo Press any key when all four have copied
pause

Have the discs got just a root drive of files, multiple sub dirs, or what?
Are they all going into one dir orr separate ones?
And if they are in subdirs on the DVD's do you want them kept in subdirs or flattened into one dir?
What about filename clashes if all in the same dir.

I

Steve
Avatar of doc_jay
doc_jay

ASKER

Thanks for responding dragon-it -- the discs just have files on them and no sub dirs.  I want all of the files from each DVD drive to go to one directory.  If there are sub dirs, then I don't want to keep the sub dirs, just flattened into one dir.  If there are any file name clashes (there shouldn't be any of them though) then you can just add a (-1 or -2) at the end of the file name.

thank you
OK in which case slightly more work but quite do-able.  For each one you need to do something like:

@echo off
set dest=x:\destination
for /f "tokens=*" %%a in (' dir /b /s /a-d d:\*.*') do (
  if exist "%dest%\%%~nxa" ... add 1 or 2 to name
  copy file to dest
)

And do that 4 times for your 4 drives.  Will come back to it later if no-one else has jumped in by then!

Steve
Avatar of doc_jay

ASKER

anyway to make it eject the DVD when its done?
One I've got bookmarked is nircmd:

http://www.winhelponline.com/blog/create-shortcuts-to-eject-and-close-cddvd-drive/

So I suppose with that you could do, roughly:

4 x threads running (= 4 x batches)

nircmd.exe cdrom open F:
put cd in and press any key
nircmd.exe cdrom close F:
do the xcopy
loop to start

So this first batch should do that for one drive, and the second will call this to make 4 threads.  It makes them quite small windows so you can see them (30 x 20) but you can adjust  in line #2:

Haven't tested but all code looks Ok to me.  Let me know if any issues.

@echo off
mode 30,20
REM call this CopyOneDvd.cmd
set dest=x:\destination
if "%~1"=="" (
  echo Call with drive letter to use, e.g. %~0 F:
  exit /b
)
set drive=%~1
:loop
  nircmd.exe cdrom open %drive%
  echo Please put the next DVD in drive %drive% and press return
  echo Type anything and return to quit
  set Choice=OK
  set /p Choice= > NUL
  if not "%Choice%"=="OK" exit /b
  nircmd.exe cdrom close %drive%
  for /F "delims=" %%a in ('dir /b /s /a-d %drive%\*.*') do call :checkfileexists "%%~a"
goto :loop

REM Pass full path and filename to this routine
REM Checks if file of same name exists in destination
REM If it does then it tries adding -1, and keeps counting until it is unique
REM then it copies the file and returns to the list

:checkfileexists
  set filename=%~n1
  set extension=%~x1
  set full=%~1
  set addunique=
  set count=1
  :loopunique
  if not exist "%destination%\%filename%%addunique%%extension%" goto OKunique
    set addunique=-%count%
    set /a count=count + 1
    goto loopunique
:OKunique
    if not "%addunique%"=="" echo Copying %full% to \%filename%%addunique%%extension%
    copy %full%" "%destination%\%filename%%addunique%%extension%"
exit /b


@echo off
REM Call This CopyAll.cmd
cd /d c:\scriptsdir
START "DVD F:" CopyOneDvd.cmd F:
START "DVD G:" CopyOneDvd.cmd G:
START "DVD H:" CopyOneDvd.cmd H:
START "DVD I:" CopyOneDvd.cmd I:


Avatar of doc_jay

ASKER

okay, I've finally got a hold of one of these DVDs that we will be copying from.  
Here is the folder structure:
Archive -->Oct2006-->randomly alpha numeric generated folder name (will never be duped)

The only value that will change here is the folder name after Archive which is the month/year name.  The only structure I need to keep are the folders inside of the month/year folder.  All of these sub folders can be dumped into the 'hold' folder or 'x:\destination'.

There will be no longer a need to have to worry about renaming any files/folders.
Avatar of doc_jay

ASKER

Sorry about earlier...I was told there was no folder structure, but there turned out to be some anyways.
Avatar of doc_jay

ASKER

What your code does above is just come back and tell me "The system cannot find the file specified.  Please put the next DVD into drive F: and press return.  Type anything and return to quit"
hmm, have you downloaded the nircmd.exe i mentioned for starters and put it in the same dir.   will need rejigging but not around to look until Sunday now probably.

Without the need to do the unique stuff pretty well can just do an xcopy of that dir to the dest dir...

Could you give an example or two pls to make sure, w.g.

Archive / oct2009 / xxxxxxx / files.txt

is xxxxxx the only subdir or are there several under the month

do you want to end up then with

x:/dest/hold/xxxxx/file.txt
x:/dest/hols/file.txt
or whatever.

Is probably clear if I re-read on pc but if you can easilyclarify is best

thanks

steve
Avatar of doc_jay

ASKER

I have nircmd.exe on the PC and that part works great.

the examples are:

the files in the subdirs under the month/year folder have no file extensions.  
Archive / oct2009 / xxxxxxx / files  (with no file extensions)
there are many XXXXXX subdirs under 'oct2009' ( the month/year will change according to when the DVD was written)
I would like to end up with the copied data as:
x:/destination directory/files
-- like all of the files that are within the XXXXXX sub dirs inside of the 'X:/destionation dirtory'


-thanks - let me know if you have any other questions.

Jamie
OK, this then should look into each drive for the first subdir, cd into it then copy any structure under that to the dest drive complete with the top level subdir:

Steve
 
@echo off
REM call this CopyOneDvd.cmd
set dest=x:\destination
if "%~1"=="" (
  echo Call with drive letter to use, e.g. %~0 F:
  exit /b
)

mode 30,20
set drive=%~1

:loop
  nircmd.exe cdrom open %drive%
  echo Please put the next DVD in drive %drive% and press return
  echo Type anything and return to quit
  set Choice=OK
  set /p Choice= > NUL
  if not "%Choice%"=="OK" exit /b
  nircmd.exe cdrom close %drive%

  REM Run down each folder in route of DVD drive - one or more if there are
  REM Copies any folders and their files under that into dest drive
  for /d %%a in (%drive%\*.*) do xcopy /e "%drive%\%%a\*.*" %dest% 
  
goto :loop


@echo off
REM Call This CopyAll.cmd
cd /d c:\scriptsdir
START "DVD F:" CopyOneDvd.cmd F:
START "DVD G:" CopyOneDvd.cmd G:
START "DVD H:" CopyOneDvd.cmd H:
START "DVD I:" CopyOneDvd.cmd I:

Open in new window

Avatar of doc_jay

ASKER

I think we are close - it can't find any files to copy -- here is the output:

Please put the next DVD in dri
ve F: and press return
Type anything and return to qu
it

File not found - *.*
0 File(s) copied
Please put the next DVD in dri
ve F: and press return
Type anything and return to qu
it

& here is the file structure of the DVD I'm using right now:
F:\Archive\Oct2006\DOEJOHN20061016123236001321656165\
--inside of that last sub-folder are 56 files with NO file extension and the 1st file is named 'CYRSWXK0' --the rest of the files are similar but are all named differently.
ok thanks, will check it out.... Thought that was what i had aimed it to copy... Maybe i missed /s off the xcopy above.  will check and come back to you later once back.
Avatar of doc_jay

ASKER

according to xcopy commands:

/s      Copies folders and subfolders except for empty ones.
/e      Copies any subfolder, even if it is empty.

I do NOT want to keep the directory structure from the DVD, I just want the files that are in each 3rd subdir.  There are NO files in any other directory except for the 3rd subdir and there are always multiple subdirs in the 3rd position.
Avatar of doc_jay

ASKER

when I edit the 'CopyoneDVD.cmd' to this:

REM Run down each folder in route of DVD drive - one or more if there are
  REM Copies any folders and their files under that into dest drive
  REM FOR /d %%a in (%drive%\*.*) do xcopy /s "%drive%\%%a\*.*" %dest%
  xcopy /s "f:\*.*" %dest%

the xcopy works fine -- just thought I would let ya know if it would help you troubleshoot.
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doc_jay

ASKER

yes sir, I can see that - very sorry!  I will try your code and thank you very much for all of your help.  Sorry for the flip flop.
Not a prob, just confused me there :-)

If any issues will run it over test dirs myself later but can't for few hours.

Steve
Avatar of doc_jay

ASKER

Steve,

  Its coming back and telling me 'The system cannot find the path specified' over and over again -- almost like its going through each folder.

Here is the code I'm using:

@echo off
mode 30,20
REM call this CopyOneDvd.cmd
set dest=D:\import\hold\
if "%~1"=="" (
  echo Call with drive letter to use, e.g. %~0 F:
  exit /b
)
set drive=%~1
:loop
  nircmd.exe cdrom open %drive%
  echo Please put the next DVD in drive %drive% and press return
  echo Type anything and return to quit
  set Choice=OK
  set /p Choice= > NUL
  if not "%Choice%"=="OK" exit /b
  nircmd.exe cdrom close %drive%
  for /F "delims=" %%a in ('dir /b /s /a-d %drive%\*.*') do copy "%%~a" "%dest% 
goto :loop

Open in new window

Avatar of doc_jay

ASKER

Steve - looks like a missed a double quote on %dest%... it work works now.  I will do more testing with multiple DVD readers
Yes that would be about right sorry, lost on copy/paste into here.  Is it working now?  I've added a bit of error checking for you below if of use.
@echo off
setlocal enabledelayedexpansion
REM call this CopyOneDvd.cmd
set dest=D:\destination
set log=D:\log.txt

if "%~1"=="" (
  echo Call with drive letter to use, e.g. %~0 F:
  exit /b
)

mode 60
set drive=%~1

:loop

  nircmd.exe cdrom open %drive%

  echo Please put the next DVD in drive %drive% and press return
  echo Type anything and return to quit
  set Choice=OK
  set /p Choice= > NUL
  if not "%Choice%"=="OK" (mode 80 & exit /b)

  nircmd.exe cdrom close %drive%

  REM Run down each folder in route of DVD drive - one or more if there are.
  REM record in log.txt file which files are copied and any errors to check

  set error=
  for /F "delims=" %%a in ('dir /b /s /a-d %drive%\*.*') do (
    echo Copying "%%~a" >>%LOG%
    copy /y "%%~a" "%dest%" >NUL 2>>%log%
    if errorlevel 1 set error=!error! %%~nxa
  )

  if not "%error%"=="" (
    echo There were errors.  See log file.
    echo.
    echo %error%
    echo.
    pause
  )
  
goto :loop

Open in new window


Steve
Avatar of doc_jay

ASKER

yes, it does work now  :)  I'm going to test tomorrow with 3 or 4 dvd readers..I'm sure it'll work flawlessly.

thanks for hangin in there with me.  Your a real pro and you know your stuff!

Jamie
Thanks, no problem!

Steve
Avatar of doc_jay

ASKER

thanks this works great!
No problem, glad we got there in the end!
Avatar of doc_jay

ASKER

hey- would anybody know how I can make winxp beep or alert me when the CD/DVD drive is ejected?   I don't have any PC speakers so using the system speaker would be ideal.

thanks
Avatar of doc_jay

ASKER

Ctrl G - figured it out - thx!
yes BEL is an easy way... Normally have to use old EDIT or something other than notepad to enter it first but once there can  use notepad ok.

Steve
Avatar of doc_jay

ASKER

Dragon-it --

So, I was hoping you could help me change the way this is working, and if you want me to post another question with a reward for points I will.  I am using the code attached  ( working great):  
@echo off
mode 30,20
REM call this CopyOneDvd.cmd
set dest=D:\import\hold\
if "%~1"=="" (
  echo Call with drive letter to use, e.g. %~0 F:
  exit /b
)
set drive=%~1
:loop
  nircmd.exe cdrom open %drive%
  echo Please put the next DVD in drive %drive% and press return
  echo Type anything and return to quit
  set Choice=OK
  set /p Choice= > NUL
  if not "%Choice%"=="OK" exit /b
  nircmd.exe cdrom close %drive%
  for /F "delims=" %%a in ('dir /b /s /a-d %drive%\*.*') do copy "%%~a" "%dest%"
goto :loop

Open in new window

and have purchased an auto loader (nimbie actually)  The code works great with the nimbie, except that I have to press enter each time it loads a DVD.  I was hoping that it could be modified to give it a 30sec wait, that way it wouldn't have to be babysat all day and it could work on 100 DVDs all night long?

thanks for all of your help on this!
Will take a look sometime this evening if I can or tomorrow if not.... Did wonder if you could buy an autoloader, much easier!

Can certainly add a pause instead of key press with as simple as replacing a PAUSE command with  

ping 127.0.0.1 -n 31 >nul 2>&1

which should pause approx. 3p secs by doing 31 pings to its loopback address.

steve
so how does it know with your autoloader to continue..... Does it need to:

open drive
close drive
copy data
open drive
close drive
copy data

or some other combination?

Steve
Avatar of doc_jay

ASKER

it actually talk to this application from Broadex Systems, QQGetTray, but yes it watches for opening and closing of the drive.  I am only using one drive now instead of four.

Jamie
Then surely you can just do without the pause altogether?  

i.e.

@echo off
set dest=D:\import\hold\
if "%~1"=="" (
  echo Call with drive letter to use, e.g. %~0 F:
  exit /b
)
set drive=%~1
:loop
  nircmd.exe cdrom open %drive%
  nircmd.exe cdrom close %drive%
  for /F "delims=" %%a in ('dir /b /s /a-d %drive%\*.*') do copy "%%~a" "%dest%"
goto :loop
Avatar of doc_jay

ASKER

yeah, your right - i'll try it out!  

thanks!