我试图创建一个复制某些文件的批处理文件,然后删除他们的#34;只读"属性。
使用Windows 8.1。
我的文件看起来像这样:
@echo off
set s1=copy successful
set s2=remove read only successful
set timer=2
XCOPY C:\my_dir_1\my_dir_2 C:\my_dir_2 /D /E /C /R /I /K /Y
echo %s1%
timeout /T %timer%
attrib -r C:\my_dir_2 /s /d
echo %s2%
timeout /T %timer%
副本工作正常,当我执行此操作时,我会在复制时看到所有文件的cmd提示符。计时器也按预期工作,但删除只读不是。提示右转到第二个计时器部分。我使用this链接作为教程。
答案 0 :(得分:2)
attrib -r C:\my_dir_2 /s /d
设置文件夹的属性。您想为文件设置它,所以:
attrib -r C:\my_dir_2\* /s /d
答案 1 :(得分:0)
我创建了这个批处理文件来执行此操作。基本上,这个批处理文件将清除其所在目录或其所在目录和所有较低目录中的只读属性。希望有人找到它的用途。请原谅任何可能看起来“差”的代码,因为我自己开始学习批处理文件。
@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