[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

copy files from multiple DVD Drives

Posted on 2011-10-20
35
Medium Priority
?
324 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:doc_jay
  • 19
  • 16
35 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37001154
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

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37001165
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
0
 

Author Comment

by:doc_jay
ID: 37001989
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
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 37002772
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
0
 

Author Comment

by:doc_jay
ID: 37002927
anyway to make it eject the DVD when its done?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37003344
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:


0
 

Author Comment

by:doc_jay
ID: 37007431
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.
0
 

Author Comment

by:doc_jay
ID: 37007572
Sorry about earlier...I was told there was no folder structure, but there turned out to be some anyways.
0
 

Author Comment

by:doc_jay
ID: 37007594
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"
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37009005
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
0
 

Author Comment

by:doc_jay
ID: 37009096
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37014196
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

0
 

Author Comment

by:doc_jay
ID: 37017753
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.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37019172
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.
0
 

Author Comment

by:doc_jay
ID: 37019256
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.
0
 

Author Comment

by:doc_jay
ID: 37019482
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.
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 37019912
Jamie,

Hmm.. so not subdirs now?

In http:#37003344 that basically did that.... all files in all subdirs up to dest drive adding 1 etc if duplicate.

In http:#37007431 you said " 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. "

So that was I then amended it to do... thogh actually then you said in http:#37014196 no subdirs too

Can see wy I was a little confused!

Anyway aside from it doing more than needed http:#37003344 will do what you need IMO.

Replace this:
 
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

Open in new window

with
 
for /F "delims=" %%a in ('dir /b /s /a-d %drive%\*.*') do copy "%%~a" "%dest% 
goto :loop

Open in new window


i.e. run down all files on dvd and copy to dest area withput checking duplicates etc.
0
 

Author Comment

by:doc_jay
ID: 37020021
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.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37020054
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
0
 

Author Comment

by:doc_jay
ID: 37020608
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

0
 

Author Comment

by:doc_jay
ID: 37020705
Steve - looks like a missed a double quote on %dest%... it work works now.  I will do more testing with multiple DVD readers
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37021182
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
0
 

Author Comment

by:doc_jay
ID: 37021231
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37021264
Thanks, no problem!

Steve
0
 

Author Comment

by:doc_jay
ID: 37024977
thanks this works great!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37025093
No problem, glad we got there in the end!
0
 

Author Comment

by:doc_jay
ID: 37183956
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
0
 

Author Comment

by:doc_jay
ID: 37184553
Ctrl G - figured it out - thx!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37184805
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
0
 

Author Comment

by:doc_jay
ID: 37292734
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!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37292983
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37293110
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
0
 

Author Comment

by:doc_jay
ID: 37293216
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37293759
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
0
 

Author Comment

by:doc_jay
ID: 37293993
yeah, your right - i'll try it out!  

thanks!
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question