Ed Walsh
asked on
Batch file to copy files
I have a large number of 3.5" floppy disks to copy off onto a hard drive.
I want to automate this so it can be done by a temp. So I will need something very simple.
Batch file came to mind BUT its been a decade or so since I wrote one.
All files will be written to F:/floppy/
I want to ask user for folder name to create/use in f:/floppy/ and then copy everything in A: to this folder.
The machine being used is a Win Vista 32 Bit.
So steps should be like:
1 Ask to give a folder name that will be created on hard drive for the files.
2 The files will be copied to F:/floppy/<name of folder you gave to question 1> Create folder if its not already created.
3. verify the files
4. when done ask to eject disk and insert next disk or quit
5 repeat to 1 (if you didn't quit)
I know this shouldn't be hard to do. But again I have forgotten my batch file skills.
Any help would be greatly appreciated.
Thank you for your time.
I want to automate this so it can be done by a temp. So I will need something very simple.
Batch file came to mind BUT its been a decade or so since I wrote one.
All files will be written to F:/floppy/
I want to ask user for folder name to create/use in f:/floppy/ and then copy everything in A: to this folder.
The machine being used is a Win Vista 32 Bit.
So steps should be like:
1 Ask to give a folder name that will be created on hard drive for the files.
2 The files will be copied to F:/floppy/<name of folder you gave to question 1> Create folder if its not already created.
3. verify the files
4. when done ask to eject disk and insert next disk or quit
5 repeat to 1 (if you didn't quit)
I know this shouldn't be hard to do. But again I have forgotten my batch file skills.
Any help would be greatly appreciated.
Thank you for your time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't have a bad disk here to test with, but I think it ought to continue.
you can use robocopy instead of xcopy. it will continue if there is a bad file.
the syntax can be: robocopy source destination /mir /w:1 /r:1
can additional use the parameter /log to write a log file
you can download robocopy inkl. a manual from http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
the syntax can be: robocopy source destination /mir /w:1 /r:1
can additional use the parameter /log to write a log file
you can download robocopy inkl. a manual from http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
hiya ewaish
I threw this together for you in XP Pro.
This should get you on your way.... I've incorporated some error handling stuff which does pad the code out considerably.
The framework is here, whether or not XP's batch language syntax is the same as Vista's.
The last time I did any real batch file stuff was back in DOS 6.2 however, it's been fun...
Please let me know if it does the job as I don't have access to Vista.
@rem ========================== ========== ========== ========== ====
@rem BATCH COPY FLOPPIES [BCF.BAT]
@rem
@rem Ask user for folder name. Copy floppies to new folder.
@rem ========================== ========== ========== ========== ====
@echo off
if "%1"=="?" goto help
if "%1"=="/?" goto help
if not "%1"=="" goto unexpected_parameter
set target_drive=f:\floppy\
set source_drive=a:\
cls
echo %0 - Copy file from floppy to [%target_drive%....]
if not exist %target_drive% goto no_target_drive
rem -------------------------- ---------- ---------- ---------- -----
rem GET FOLDER NAME
rem -------------------------- ---------- ---------- ---------- -----
:get_folder_name
echo.
set folder_name=
set /p folder_name="Enter new folder: "
if "%folder_name%"=="" goto no_folder_name
if exist %target_drive%%folder_name % goto folder_exists
rem -------------------------- ---------- ---------- ---------- -----
rem CREATE FOLDER
rem -------------------------- ---------- ---------- ---------- -----
mkdir %target_drive%%folder_name %>nul
if "%errorkevel%"=="1" goto bad_folder_name
rem -------------------------- ---------- ---------- ---------- -----
rem INSERT FLOPPY
rem -------------------------- ---------- ---------- ---------- -----
:insert_floppy_disk
echo.
echo Insert floppy disk in drive A:
echo.
pause
if not exist %source_drive% goto no_source_drive
rem -------------------------- ---------- ---------- ---------- -----
rem COPY FILES
rem -------------------------- ---------- ---------- ---------- -----
:copy_files
echo.
echo Copying files from %source_drive% to %target_drive%%folder_name %
echo.
xcopy %source_drive%*.* %target_drive%%folder_name % /s /e /v /c /g /h /q /r /o /y
echo Finished copying files. Please remove disk from drive A:
rem -------------------------- ---------- ---------- ---------- -----
rem COPY ANOTHER FLOPPY?
rem -------------------------- ---------- ---------- ---------- -----
:continue_copying
echo.
set input=
set /p input="Would you like to copy another floppy [Y/N]: "
if "%input%"=="y" goto insert_floppy_disk
if "%input%"=="Y" goto insert_floppy_disk
if "%input%"=="n" goto finish_copying
if "%input%"=="N" goto finish_copying
goto continue_copying
rem ========================== ========== ========== ========== =====
rem ERROR HANDLERS
rem ========================== ========== ========== ========== =====
rem -------------------------- ---------- ---------- ---------- -----
rem HELP
rem -------------------------- ---------- ---------- ---------- -----
:help
echo.
echo Copy floppy disks to hard drive %source_drive%[folder_name ]
echo.
echo %0
echo %0 [/?]
echo.
goto end
rem -------------------------- ---------- ---------- ---------- -----
rem UNEXPECTED PARAMETER
rem -------------------------- ---------- ---------- ---------- -----
:unexpected_parameter
echo.
echo Unexpected parameter on command line following [%0]
echo.
echo Type %0 /? for help.
echo.
goto end
rem -------------------------- ---------- ---------- ---------- -----
rem NO TARGET DRIVE
rem -------------------------- ---------- ---------- ---------- -----
:no_target_drive
echo.
echo [%target_drive%] drive is not ready or does not exist.
echo.
goto end
rem -------------------------- ---------- ---------- ---------- -----
rem NO FOLDER NAME
rem -------------------------- ---------- ---------- ---------- -----
:no_folder_name
echo.
echo You must enter a folder name to copy files to.
echo.
set input=
set /p input=Would you like to continue copying files [Y/N]: "
if "%input%"=="y" goto get_folder_name
if "%input%"=="Y" goto get_folder_name
if "%input%"=="n" goto end
if "%input%"=="N" goto end
goto no_folder_name
rem -------------------------- ---------- ---------- ---------- -----
rem FOLDER EXISTS
rem -------------------------- ---------- ---------- ---------- -----
:folder_exists
echo.
echo The folder [%folder_name%] already exists.
echo.
set input=
set /p input="[c]ontinue with [%folder_name%] or [e]nter new folder name: "
if "%input%"=="c" goto insert_floppy_disk
if "%input%"=="C" goto insert_floppy_disk
if "%input%"=="e" goto get_folder_name
if "%input%"=="E" goto get_folder_name
goto folder_exists
rem -------------------------- ---------- ---------- ---------- -----
rem BAD FOLDER NAME
rem -------------------------- ---------- ---------- ---------- -----
:bad_folder_name
echo.
echo There is a problem with the folder name [%folder_name%].
echo.
set input=
set /p input=" Would you like [e]nter a new folder name or [a]bort: "
if "%input%"=="e" goto get_folder_name
if "%input%"=="E" goto get_folder_name
if "%input%"=="a" goto end
if "%input%"=="A" goto end
goto bad_folder_name
rem -------------------------- ---------- ---------- ---------- -----
rem NO SOURCE DRIVE
rem -------------------------- ---------- ---------- ---------- -----
:no_source_drive
echo.
set input=
set /p input="No disk in drive A: [a]bort or [c]ontinue: "
if "%input%"=="a" goto finish_copying
if "%input%"=="A" goto finish_copying
if "%input%"=="c" goto insert_floppy_disk
if "%input%"=="C" goto insert_floppy_disk
goto no_source_drive
rem -------------------------- ---------- ---------- ---------- -----
rem FINISH COPYING
rem -------------------------- ---------- ---------- ---------- -----
:finish_copying
echo.
echo End of floppy disk transfer program.
echo.
rem -------------------------- ---------- ---------- ---------- -----
rem END
rem -------------------------- ---------- ---------- ---------- -----
:end
echo.
set input=
set folder_name=
set target_drive=
set source_drive=
I threw this together for you in XP Pro.
This should get you on your way.... I've incorporated some error handling stuff which does pad the code out considerably.
The framework is here, whether or not XP's batch language syntax is the same as Vista's.
The last time I did any real batch file stuff was back in DOS 6.2 however, it's been fun...
Please let me know if it does the job as I don't have access to Vista.
@rem ==========================
@rem BATCH COPY FLOPPIES [BCF.BAT]
@rem
@rem Ask user for folder name. Copy floppies to new folder.
@rem ==========================
@echo off
if "%1"=="?" goto help
if "%1"=="/?" goto help
if not "%1"=="" goto unexpected_parameter
set target_drive=f:\floppy\
set source_drive=a:\
cls
echo %0 - Copy file from floppy to [%target_drive%....]
if not exist %target_drive% goto no_target_drive
rem --------------------------
rem GET FOLDER NAME
rem --------------------------
:get_folder_name
echo.
set folder_name=
set /p folder_name="Enter new folder: "
if "%folder_name%"=="" goto no_folder_name
if exist %target_drive%%folder_name
rem --------------------------
rem CREATE FOLDER
rem --------------------------
mkdir %target_drive%%folder_name
if "%errorkevel%"=="1" goto bad_folder_name
rem --------------------------
rem INSERT FLOPPY
rem --------------------------
:insert_floppy_disk
echo.
echo Insert floppy disk in drive A:
echo.
pause
if not exist %source_drive% goto no_source_drive
rem --------------------------
rem COPY FILES
rem --------------------------
:copy_files
echo.
echo Copying files from %source_drive% to %target_drive%%folder_name
echo.
xcopy %source_drive%*.* %target_drive%%folder_name
echo Finished copying files. Please remove disk from drive A:
rem --------------------------
rem COPY ANOTHER FLOPPY?
rem --------------------------
:continue_copying
echo.
set input=
set /p input="Would you like to copy another floppy [Y/N]: "
if "%input%"=="y" goto insert_floppy_disk
if "%input%"=="Y" goto insert_floppy_disk
if "%input%"=="n" goto finish_copying
if "%input%"=="N" goto finish_copying
goto continue_copying
rem ==========================
rem ERROR HANDLERS
rem ==========================
rem --------------------------
rem HELP
rem --------------------------
:help
echo.
echo Copy floppy disks to hard drive %source_drive%[folder_name
echo.
echo %0
echo %0 [/?]
echo.
goto end
rem --------------------------
rem UNEXPECTED PARAMETER
rem --------------------------
:unexpected_parameter
echo.
echo Unexpected parameter on command line following [%0]
echo.
echo Type %0 /? for help.
echo.
goto end
rem --------------------------
rem NO TARGET DRIVE
rem --------------------------
:no_target_drive
echo.
echo [%target_drive%] drive is not ready or does not exist.
echo.
goto end
rem --------------------------
rem NO FOLDER NAME
rem --------------------------
:no_folder_name
echo.
echo You must enter a folder name to copy files to.
echo.
set input=
set /p input=Would you like to continue copying files [Y/N]: "
if "%input%"=="y" goto get_folder_name
if "%input%"=="Y" goto get_folder_name
if "%input%"=="n" goto end
if "%input%"=="N" goto end
goto no_folder_name
rem --------------------------
rem FOLDER EXISTS
rem --------------------------
:folder_exists
echo.
echo The folder [%folder_name%] already exists.
echo.
set input=
set /p input="[c]ontinue with [%folder_name%] or [e]nter new folder name: "
if "%input%"=="c" goto insert_floppy_disk
if "%input%"=="C" goto insert_floppy_disk
if "%input%"=="e" goto get_folder_name
if "%input%"=="E" goto get_folder_name
goto folder_exists
rem --------------------------
rem BAD FOLDER NAME
rem --------------------------
:bad_folder_name
echo.
echo There is a problem with the folder name [%folder_name%].
echo.
set input=
set /p input=" Would you like [e]nter a new folder name or [a]bort: "
if "%input%"=="e" goto get_folder_name
if "%input%"=="E" goto get_folder_name
if "%input%"=="a" goto end
if "%input%"=="A" goto end
goto bad_folder_name
rem --------------------------
rem NO SOURCE DRIVE
rem --------------------------
:no_source_drive
echo.
set input=
set /p input="No disk in drive A: [a]bort or [c]ontinue: "
if "%input%"=="a" goto finish_copying
if "%input%"=="A" goto finish_copying
if "%input%"=="c" goto insert_floppy_disk
if "%input%"=="C" goto insert_floppy_disk
goto no_source_drive
rem --------------------------
rem FINISH COPYING
rem --------------------------
:finish_copying
echo.
echo End of floppy disk transfer program.
echo.
rem --------------------------
rem END
rem --------------------------
:end
echo.
set input=
set folder_name=
set target_drive=
set source_drive=
ASKER
t0t0:
Your script didn't work on my Vista Home Pro machine.
I see the DOS box open and then close. I tried with extension bat & cmd neither worked.
I like however how you added alot of safe guards and checking.
If you could get this to work on Vista I would use it.
However, Shift-3 did provide exactly what I asked for and it worked like a charm.
Sorry for such a long delay in accepting the answer.
t0t0: If you do get your script working, please comment it onto this post/question.
Ed W.
Your script didn't work on my Vista Home Pro machine.
I see the DOS box open and then close. I tried with extension bat & cmd neither worked.
I like however how you added alot of safe guards and checking.
If you could get this to work on Vista I would use it.
However, Shift-3 did provide exactly what I asked for and it worked like a charm.
Sorry for such a long delay in accepting the answer.
t0t0: If you do get your script working, please comment it onto this post/question.
Ed W.
ASKER
Question.
I manually copied a couple of disks. A few disks had a file that couldn't be copied. Got a dialog box telling me they couldn't be read/copied and if I wanted to Retry, skip, quit.
If I get a bad file like that, will this batch file fail?