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

Hoe verwijder ik recursief een alleen-lezen attribuut op Windows 7

Advertisement

Ik moet de alleen-lezen attributen van alle bestanden onder een map recursief verwijderen op Windows 7 met behulp van de opdrachtregel. Kunt u hier een voorbeeld van geven?

Advertisement
Advertisement

Antwoorden (5)

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

Ik zou het ATTRIB commando gebruiken, bijvoorbeeld:

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

attrib is het commando -r is de vlag voor het verwijderen van alleen-lezen attributen c:\folder\*.* is de map waar je het op uitvoert, plus wildcards voor alle bestanden /s is de vlag voor het doen van alle subdirectories en bestanden

Hier is wat meer documentatie en voorbeelden voor het attrib commando: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/attrib

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

Open eerst een opdrachtprompt. Ga dan cd naar de map waar u de attribuutwijzigingen wilt gaan toepassen. Voer tenslotte het volgende commando in:

attrib -R /S

Dat verwijdert het alleen-lezen attribuut van alle bestanden in de huidige directory, en gaat dan naar beneden om hetzelfde te doen in alle subdirectories.

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

Note: De meeste andere antwoorden gebruiken alleen -r wat misschien niet werkt op bestanden die system of hidden attributen hebben.

Dus hier is een oplossing voor het recursief verwijderen van het alleen-lezen attribuut van alle bestanden (inclusief de bestanden die systeem- of verborgen zijn) in een directory:

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

Omschrijving: -s Verwijder systeemkenmerk -h Verwijder verborgen kenmerk -r Verwijder alleen-lezen kenmerk/s Instellen/verwijderen kenmerken in huidige map en inclusief submappen/d Ook kenmerken van mappen instellen/verwijderen

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

Ik heb dit batchbestand gemaakt om dit te doen. In principe zal dit batch-bestand alleen-lezen attributen wissen in de map waar het in staat of de map waar het in staat en alle lagere mappen. Hopelijk heeft iemand er iets aan. Sorry voor de slechte code, want ik begin net zelf batch bestanden te leren.

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

Veel opties hier, maar dit batchbestand ondersteunt het droppen van mappen en/of bestanden naar het batchbestand zelf.

Sla deze code hieronder op in Read-only Off.bat.

Let op hoe de drop bit werkt binnen de code.

@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
Advertisement

Gerelateerde vragen

3
28
13
7
7
Advertisement