Vicki05
asked on
Transfer data from external hard drive to another drive using variable drive path
Hi All,
I need to retreive data from a hard drive from computers that failed. My plan is to plug the hard drive as a external drive and retrieve the data to another external or local disk C: . Is there a way I would like to have the batch file ask for the drive letter where the data is stored before running and backup to current drive?
Please advice.
Thanks,
Vicki
I need to retreive data from a hard drive from computers that failed. My plan is to plug the hard drive as a external drive and retrieve the data to another external or local disk C: . Is there a way I would like to have the batch file ask for the drive letter where the data is stored before running and backup to current drive?
Please advice.
Thanks,
Vicki
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Correction, sorry; missed some percent signs in line 8:
@echo off
setlocal
:Loop
set Drive=
set /p Drive=Please enter the drive letter for the backup:
if "%Drive%"=="" goto :eof
if not "%Drive:~-1%"==":" set Drive=%Drive%:
dir Drive >NUL 2>&1
if errorlevel 1 (
echo Drive %Drive% not found.
goto :Loop
)
set Source=C:\
set Target=%Drive%\
ECHO robocopy.exe %Source% %Target% /e /r:0 /w:0
You could always give a little bit of a helping hand to choosing the drive too with a command at the top of your script to show some info, .e.g
@echo off
WMIC logicaldisk get caption, volumename, description, size, freespace
Set Drive=
set /p Drive = etc.
@echo off
WMIC logicaldisk get caption, volumename, description, size, freespace
Set Drive=
set /p Drive = etc.
Or even:
@echo off
echo Set objShell = CreateObject^( "Shell.Application" ^) > "%temp%\getpath.vbs"
echo set objFolder = objShell.BrowseForFolder^( 0, "Select a drive", ^&H10^&, ""^)>> "%temp%\getpath.vbs"
echo wscript.echo objFolder.Self.Path >> "%temp%\getpath.vbs"
for /f "tokens=*" %%a in ('cscript //nologo "%temp%\getpath.vbs"') do set folder=%%a
echo Now do copy from %folder:~0,2%
pause
@echo off
echo Set objShell = CreateObject^( "Shell.Application" ^) > "%temp%\getpath.vbs"
echo set objFolder = objShell.BrowseForFolder^(
echo wscript.echo objFolder.Self.Path >> "%temp%\getpath.vbs"
for /f "tokens=*" %%a in ('cscript //nologo "%temp%\getpath.vbs"') do set folder=%%a
echo Now do copy from %folder:~0,2%
pause
ASKER
Hi oBdA,
I am getting drive letter not found.
Hi Bill,
I am able to continue with the method you have suggested however, I need to be able to enter the source drive and be able to backup to current drive which can be a external drive as well.
Is that a possibility?
Something like
xcopy /q/y "%Drive%:\Test\Backup\*.*" %Current_Drive%:\
I am getting drive letter not found.
Hi Bill,
I am able to continue with the method you have suggested however, I need to be able to enter the source drive and be able to backup to current drive which can be a external drive as well.
Is that a possibility?
Something like
xcopy /q/y "%Drive%:\Test\Backup\*.*"
For the current drive you can just not specify a drive, i.e. \path\file is for the current drive or you can get the current directory using %cd%. From that %cd~0,2% should be the drive letter.
Steve
Steve
Hi Bill,My solution certainly allowed that, just adjust the destination of whatever copy command you use to specify the destination relative to whatever will be the current directory.
I am able to continue with the method you have suggested however, I need to be able to enter the source drive and be able to backup to current drive which can be a external drive as well.
~bp
Did you see my second comment? The first version was missing the percent sign around "Drive" in line 6.
If the script is stored on the external drive, you can just use %~dp0 to access the drive.
If the script is stored on the external drive, you can just use %~dp0 to access the drive.
@echo off
setlocal
:Loop
set Drive=
set /p Drive=Please enter the drive letter to backup:
if "%Drive%"=="" goto :eof
if not "%Drive:~-1%"==":" set Drive=%Drive%:
dir Drive >NUL 2>&1
if errorlevel 1 (
echo Drive %Drive% not found.
goto :Loop
)
set Source=%Drive%\
set Target=%~dp0\
ECHO robocopy.exe %Source% %Target% /e /r:0 /w:0
ASKER
Thanks for your help.
ASKER
Hi oBdA,
When I run the batch file, I get a error when I enter the drive letter. Please try to run it yourself.
@echo off
setlocal
:Loop
set Drive=
set /p Drive=Please enter the drive letter to backup:
if "%Drive%"=="" goto :eof
if not "%Drive:~-1%"==":" set Drive=%Drive%:
dir Drive >NUL 2>&1
if errorlevel 1 (
echo Drive %Drive% not found.
goto :Loop
)
set Source=%Drive%\
set Target=%~dp0\
ECHO robocopy.exe %Source% %Target% /e /r:0 /w:0
When I run the batch file, I get a error when I enter the drive letter. Please try to run it yourself.
@echo off
setlocal
:Loop
set Drive=
set /p Drive=Please enter the drive letter to backup:
if "%Drive%"=="" goto :eof
if not "%Drive:~-1%"==":" set Drive=%Drive%:
dir Drive >NUL 2>&1
if errorlevel 1 (
echo Drive %Drive% not found.
goto :Loop
)
set Source=%Drive%\
set Target=%~dp0\
ECHO robocopy.exe %Source% %Target% /e /r:0 /w:0
Line 8 had % % missing too. %Drive% instead of Drive
Steve
Steve
Open in new window