2013-10-03 15:49:37 +0000 2013-10-03 15:49:37 +0000
72
72

如何在Windows 7上递归删除只读属性?

我需要在Windows 7上用命令行递归地删除一个目录下所有文件的只读属性。请你提供一个这方面的例子。

答案 (5)

91
91
91
2013-10-03 15:56:07 +0000

我会使用ATTRIB命令,例如:

attrib -r c:\folder\*.* /s

attrib 是命令 -r 是删除只读属性的标志 c:\folder\*.* 是你正在运行的文件夹,加上所有文件的通配符 /s 是做所有子目录和文件的标志

这里有更多关于attrib命令的文档和例子。 https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/attrib

25
25
25
2013-10-03 15:57:44 +0000

首先,打开一个命令提示符。然后cd到你要开始应用属性更改的目录中。最后,输入以下命令。

attrib -R /S

这样就会把当前目录下所有文件的只读属性去掉 然后在所有的子目录下进行同样的操作。

11
11
11
2017-04-13 11:44:22 +0000

注意:其他的答案大多只使用-r,这对设置了systemhidden属性的文件可能**不起作用。

所以这里有一个解决方案,可以递归地从目录内的所有文件(包括那些系统或隐藏的文件)中删除只读属性。

attrib -s -h -r "c:\path_to_folder\*.*" /s /d

描述: -s 删除系统属性 -h 删除隐藏属性 -r 删除只读属性/s 设置/删除当前文件夹和包括子文件夹的属性/d 也设置/删除文件夹的属性。

2
2
2
2017-07-17 15:40:44 +0000

我创建了这个批处理文件来做这件事。基本上这个批处理文件将清除其所在目录或其所在目录和所有下级目录中的只读属性。希望有人能找到它的用途。请原谅任何看似 “拙劣 "的代码,因为我自己也是刚开始学习批处理文件。

@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
0
0
0
2019-07-14 16:54:55 +0000

这里有很多选项,但这个批处理文件支持将文件夹/s和/或文件/s放到批处理文件本身。

将下面这段代码保存到Read-only Off.bat

注意代码中的drop位如何工作。

@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