@echo off

rem 引数が無い場合 コマンドが実行されたフォルダとフォルダー内のcfgファイルの読み取り専用を解除します。
if "%~1"=="" ( 
	echo.
	echo -----+--before check---------------------------------------------------------------------------------
	attrib  %CD%
	attrib  %~dp0*.cfg
	echo -----+-----------------------------------------------------------------------------------------------
	echo.

	rem コマンド実行
	attrib -r %CD%
	attrib -r %~dp0*.cfg

	echo.
	echo -----+--after check----------------------------------------------------------------------------------
	attrib  %CD%
	attrib  %~dp0*.cfg
	echo -----+-----------------------------------------------------------------------------------------------
	echo.
rem デバッグ用pause
rem pause
	exit /b


rem 引数が有る場合 フォルダかファイルを判定して読み取り専用を解除
) else (
	echo.
	echo Input = %1
	rem ファイル・フォルダ判定
	if exist %1%\ (
		set check_a=FD

		echo フォルダが指定されました。
		echo Folder was appointed.
		echo.
		echo 以下の[フォルダー]及び[フォルダー内のcfgファイル]の読み取り専用を解除します。
		echo The readonly folders and cfg files in the folder are changed to read/write.
		echo.
	) else (
		set check_a=0
		echo ファイルが指定されました。
		echo File was appointed.
		echo.
		echo 以下のファイルの読み取り専用を解除します。
		echo The readonly file are changed to read/write.
		echo.
	)
)

rem 実施前確認
	echo -----+--before check---------------------------------------------------------------------------------
IF "%check_a%" == "FD" (
	rem  フォルダーの場合
	attrib %1
	attrib %1\*.cfg

) ELSE (
	rem  ファイルの場合
	attrib /s /d %1
)
echo -----+-----------------------------------------------------------------------------------------------

rem コマンド実行
if "%check_a%" == "FD" (
	rem フォルダーの場合
	rem echo /// release read only folder ///

	attrib -r /s /d %1
	rem attrib -r /s /d %1\*.cfg //サブフォルダーの下のcfgファイルもreadonly解除するコマンド
	attrib -r %1\*.cfg

) else (
	rem ファイルの場合
	rem echo /// release read only file ///
	attrib -r /s /d %1
)

echo. 

rem 実施後確認
echo -----+--after check----------------------------------------------------------------------------------
if "%check_a%" == "FD" (
	rem フォルダーの場合
	attrib %1
	attrib %1\*.cfg
) else (
	rem ファイルの場合
	attrib /s /d %1
)
echo -----+-----------------------------------------------------------------------------------------------
rem デバッグ用pause
rem pause
echo. 
