@echo off
setlocal EnableDelayedExpansion
:: --- НАСТРОЙКИ ---
set "SCRIPT_DIR=%~dp0"
set "FOLDER_NAME=SecretFolder"
set "TARGET_PATH=%SCRIPT_DIR%%FOLDER_NAME%"
set "CORRECT_PASSWORD=Alex39IT"
:: ----------------
:: Если папки нет — создаём и выходим (первый запуск)
if not exist "%TARGET_PATH%" (
echo Creating initial folder: %FOLDER_NAME%
mkdir "%TARGET_PATH%"
echo Folder created. Place your files inside it.
echo Run this script again to lock/unlock it.
pause
exit /b 0
)
:: Проверка: скрыта ли папка сейчас (наличие атрибута H)
for /f "tokens=*" %%i in ('dir /ah "%TARGET_PATH%" 2^>nul') do set "IS_HIDDEN=1"
if defined IS_HIDDEN (
:: --- РАЗБЛОКИРОВКА (показать папку) ---
echo Enter password to unlock folder:
set /p "USER_PASS="
if not "!USER_PASS!"=="!CORRECT_PASSWORD!" (
echo.
echo ERROR: Wrong password.
pause
exit /b 1
)
echo Password accepted. Unlocking folder...
attrib -h -s "%TARGET_PATH%"
start "" explorer "%TARGET_PATH%"
echo.
echo Folder is now visible. Close the window manually when ready.
echo When you close this CMD window, the folder will be hidden again.
pause
:: Автоматическое скрытие при выходе из блока (если пользователь нажал Pause и закрыл)
attrib +h +s "%TARGET_PATH%"
echo Folder hidden.
) else (
:: --- БЛОКИРОВКА (скрыть папку) ---
echo Enter password to lock folder:
set /p "USER_PASS="
if not "!USER_PASS!"=="!CORRECT_PASSWORD!" (
echo.
echo ERROR: Wrong password.
pause
exit /b 1
)
echo Password accepted. Hiding folder...
attrib +h +s "%TARGET_PATH%"
echo Folder hidden. It still exists on disk with all files.
echo Run this script again to unlock.
pause
)
endlocal