Last active
January 29, 2024 12:45
-
-
Save mfedatto/3db2bea5bbf55948d07d4a2d3a0cad45 to your computer and use it in GitHub Desktop.
map-network-path.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enabledelayedexpansion | |
REM Defina as variáveis padrão | |
set "drive_letter=" | |
set "network_path=" | |
set "label=" | |
REM Analise os argumentos nomeados | |
for %%i in (%*) do ( | |
if /I "%%~i"=="--drive-letter" ( | |
set "drive_letter=%%~i" | |
) else if /I "%%~i"=="--network-path" ( | |
set "network_path=%%~i" | |
) else if /I "%%~i"=="--label" ( | |
set "label=%%~i" | |
) | |
) | |
REM Verifique se ambos os argumentos obrigatórios foram fornecidos | |
if not defined drive_letter ( | |
echo Argumento --drive-letter não fornecido. | |
goto :eof | |
) | |
if not defined network_path ( | |
echo Argumento --network-path não fornecido. | |
goto :eof | |
) | |
REM Extraia apenas as letras da unidade (ignorando os dois-pontos) | |
set "drive_letter=!drive_letter:~2,1!" | |
REM Mapeie a unidade de rede com o rótulo especificado | |
if defined label ( | |
net use !drive_letter!: !network_path! /LABEL:"!label!" | |
) else ( | |
net use !drive_letter!: !network_path! | |
) | |
REM Verifique se o mapeamento foi bem-sucedido | |
if %errorlevel% equ 0 ( | |
echo Mapeamento bem-sucedido: !network_path! foi mapeado como !drive_letter!: com o rótulo "!label!" no Explorer. | |
) else ( | |
echo Falha no mapeamento. Código de erro: %errorlevel% | |
) | |
:end | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment