How do I get a batch to be docked in a folder for a backup operation on a thumb drive where the drive letter always changes example:
@echo off
mkdir ..\subs
move /y .\*.srt ..\subs
pause
exit
How do I get a batch to be docked in a folder for a backup operation on a thumb drive where the drive letter always changes example:
@echo off
mkdir ..\subs
move /y .\*.srt ..\subs
pause
exit
You can use the pushd
command to change the working directory , pass %~dp0
to indicate directory of the .bat
file, see an example:
@echo off
echo Diretorio atual %cd%
echo Diretorio do script %~dp0
REM Altera o diretório atual de trabalho
pushd %~dp0
echo Diretorio atual %cd%
pause
When using pushd %~dp0
you indicate that the current directory is where the file is located.
Output:
Diretorio atual C:\Users\<usuario> Diretorio do script C:\Users\<usuario>\local\do\batch\ Diretorio atual C:\Users\<usuario>\local\do\batch\ Pressione qualquer tecla para continuar. . .
The pendrive has to have some mark to be checked. Can it be like this: You create the \ subs folder on the pendrive you are going to use for backup and put the code below into the folder.
@echo off
if EXIST d:\subs\*.srt set PENDRIVE=D:&goto backup
if EXIST e:\subs\*.srt set PENDRIVE=E:&goto backup
if EXIST f:\subs\*.srt set PENDRIVE=F:&goto backup
if EXIST g:\subs\*.srt set PENDRIVE=G:&goto backup
rem Acrescente outros Drives se quiser
echo NENHUM PENDRIVE ENCONTRADO.
goto fim
:backup
move /y .\*.srt %PENDRIVE%\subs
:fim
pause