Solved

Batch file to copy files

Posted on 2008-10-10
6
766 Views
Last Modified: 2013-11-10
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.
0
Comment
Question by:ewalsh
6 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22691014
Paste the script below into a text file with a .cmd extension.


@echo off

setlocal
 

set root=f:\floppy
 

:_floppycopy

echo Insert floppy to be copied.

pause
 

set /P folder=Enter a folder name: 

if not defined folder goto :_floppycopy
 

xcopy a:\*.* "%root%\%folder%\" /E /V /C /H /R /Y > NUL
 

echo Files copied.  Please eject the floppy.

echo.
 

:_prompt

set /P continue=(C)ontinue or (Q)uit? 

if /I "%continue%"=="c" goto :_floppycopy

if /I "%continue%"=="q" goto :eof

goto :_prompt

Open in new window

0
 

Author Comment

by:ewalsh
ID: 22691079
Thank you for the fast reply.

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?
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 22691141
I don't have a bad disk here to test with, but I think it ought to continue.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Expert Comment

by:nixgibs
ID: 22714811
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
0
 
LVL 16

Expert Comment

by:t0t0
ID: 22751675
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=





0
 

Author Comment

by:ewalsh
ID: 23117708
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
listing all functions in JavaScript 19 177
Active DirectoryScript to change the Pager Field 1 48
Plain Text Editor for iPad 6 59
batch script 3 21
This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now