如何在 Windows 上遞歸刪除唯讀屬性

如何在 Windows 上遞歸刪除唯讀屬性

我需要使用命令列在 Windows 上遞歸地刪除目錄下所有檔案的唯讀屬性。您能舉個例子嗎?

答案1

我會使用 ATTRIB 指令,例如:

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

attrib是命令
-r是用於刪除唯讀屬性的標誌
c:\folder\*.*是您正在運行它的資料夾,加上所有檔案的通配符
/s是用於執行所有子目錄和檔案的標誌

以下是 attrib 命令的更多文件和範例: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/attrib

答案2

首先,打開命令提示字元。然後cd進入要開始應用屬性變更的目錄。最後,輸入以下命令:

 attrib -R /S

這將從目前目錄中的所有檔案中刪除唯讀屬性,然後它將向下遞歸以在所有子目錄中執行相同的操作。

答案3

筆記:大多數其他答案僅使用-r可能不行system在已設定屬性的檔案上hidden

所以這是一個遞歸地刪除只讀屬性的解決方案全部目錄中的檔案(包括系統檔案或隱藏檔案):

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

描述:
-s刪除系統屬性
-h刪除隱藏屬性
-r刪除唯讀屬性
/s設定/刪除目前資料夾及其子資料夾的屬性
/d也設定/刪除資料夾的屬性

答案4

這裡有很多選項,但該批次檔支援將資料夾和/或檔案拖放到批次檔本身。

將下面的程式碼儲存到Read-only Off.bat.

請注意程式碼中 drop bit 的工作原理。

@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

相關內容