Answers:
我将使用ATTRIB命令,例如:
attrib -r c:\folder\*.* /s
attrib
是命令,
-r
是删除只读属性的标志,
c:\folder\*.*
是您正在其上运行的文件夹
/s
的标志,加上所有文件的通配符,是执行所有子目录和文件的标志
这是attrib命令的更多文档和示例:https : //docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/attrib
/d
如果您还希望它也处理实际的文件夹,请添加一个。
attrib -h -r
)。
我创建了此批处理文件来执行此操作。基本上,该批处理文件将清除其所在目录或其中的目录以及所有较低目录中的只读属性。希望有人能找到它的用处。请原谅我刚刚开始学习批处理文件的任何看似“较差”的代码。
@ECHO off
:begin
ECHO Would you like to only remove read only attributes
ECHO from this director or from all the sub directores as
ECHO well?
ECHO.
ECHO [A] This directory only
ECHO [B] All directories - cascading
ECHO [C] Cancel
SET /P actionChoice="Option(A,B,C): "
ECHO.
IF "%actionChoice%" == "A" GOTO A
IF "%actionChoice%" == "B" GOTO B
IF "%actionChoice%" == "C" GOTO C
GOTO badChoice
:A
CLS
ECHO Are you sure you want to remove all read-only
ECHO attributes from this directory only?
ECHO.
ECHO Directory:
ECHO.
ECHO %CD%
ECHO.
SET /P continueChoice="Continue? (Y, N): "
IF "%continueChoice%" == "N" GOTO abort
ECHO Removing Read Only Attributes From Local Directory...
SET currectDirectory=%CD%
ECHO Current directory is: %currectDirectory%
FOR %%G IN (%currectDirectory%\*) DO (
ECHO %%G
ATTRIB -R "%%G"
)
GOTO end
:B
CLS
ECHO Are you sure you want to remove all read-only
ECHO attributes from this directory and all sub-directories?
ECHO.
ECHO Directory:
ECHO.
ECHO %CD%
ECHO.
SET /P continueChoice="Continue? (Y, N): "
IF "%continueChoice%" == "N" GOTO abort
ECHO Removing Read Only Attributes Cascading...
FOR /R %%f IN (*) DO (
ECHO %%f
ATTRIB -R "%%f"
)
GOTO end
:C
CLS
ECHO Cancel: no files have been changed
GOTO end
:badChoice
CLS
ECHO Unknown Option
ECHO.
ECHO.
ECHO.
GOTO begin
:abort
CLS
ECHO No files have been changed
ECHO.
ECHO.
ECHO.
GOTO begin
:end
ECHO Read only attributes removed
PAUSE
这里有很多选项,但是此批处理文件支持将文件夹和/或文件拖放到批处理文件本身。
将此代码保存到以下位置Read-only Off.bat
。
请注意放置位在代码内部的工作方式。
@echo off
title ' %~nx0 ' by stephen147
color 5F
rem Place this inside a folder and run to remove the read-only attribute in the root folder and any folders or files within.
rem Or drop the folder/s and/or file/s to the batch file itself.
cd /d "%~dp0"
echo.
echo.Do you want to remove the read-only attributes inside this folder ? [ Ctrl + C to cancel ]
echo.
pause
echo.
echo.%cd%
attrib -s -d -r "%cd%\*.*"
attrib -s -d -r "%cd%"
rem This line supports dropping the folder/s and/or file/s to the batch file itself.
attrib -r "%*"
echo.
echo.Done
timeout /T 5
EXIT
attrib /S -R