2014-10-03 65 views
0

我想切换具有相应属性-h & +h的目录。在批处理文件中创建切换“切换”

当我使用这个命令序列输出

\directory was unexpected at the time. 

如何得到这个工作任何想法?

:toggle 
if attrib \directory /s /d equ -h goto hidedir 
if attrib \directory /s /d equ +h goto showdir 
pause 
goto start 

:showdir 
attrib -r -s -h \directory /s /d 
goto start 

:hidedir 
attrib +r +s +h \directory /s /d 
goto start 
+0

你可以'attrib'命令不使用'IF',你需要一个'FOR ... LOOP'像这样:http://stackoverflow.com/questions/18658509/how-to-get-attributes-ofa-a-文件使用批处理文件 – LittleBobbyTables 2014-10-03 15:42:11

回答

0

这里是一个小批量代码来切换使用的技术的指定的目录的隐藏的属性作为问题How to get attributes of a file using batch file?

@echo off 
set "Directory=C:\Temp\Test Directory" 
for %%D in ("%Directory%") do set "Attributes=%%~aD" 
if "%Attributes:~3,1%"=="h" goto UnhideDir 

%SystemRoot%\System32\attrib.exe +h "%Directory%" 
goto :EOF 

:UnhideDir 
%SystemRoot%\System32\attrib.exe -h "%Directory%" 

所需的信息通过输入在理解FOR环和%%~aD是输出解释命令提示符窗口for /?help for

并运行在命令提示符窗口set /?help set和阅读印刷的帮助有助于了解IF条件的字符串比较刚刚第四个字符字符串与目录的属性进行比较。

0
@echo off 
    setlocal enableextensions disabledelayedexpansion 

    rem Configure folder to process 
    set "folder=.\test" 

    rem Determine the needed attribute 
    set "newMode=+h" 
    for %%f in ("%folder%") do for /f "tokens=2 delims=h" %%a in ("%%~af") do set "newMode=-h" 

    rem Change the attribute to new mode for the indicated folder and its contents 
    "%systemRoot%\system32\attrib.exe" %newMode% "%folder%" 
    "%systemRoot%\system32\attrib.exe" %newMode% "%folder%\*" /s /d 

在该代码for(初字符与索引值0标记)被用来获得到该文件夹​​的引用和for /f,以确定在列表中h ATTRIB的存在的文件夹的属性。变量%newMode%将获得所需的attrib命令的参数来调整该文件夹的属性的内容

0
@echo off 
setlocal 
attrib \directory /d | findstr "^....H" && set "switch=-" || set "switch=+" 
attrib %switch%r %switch%s %switch%h \directory /s /d 
-1

我想,这可能有助于只是改变了链接,什么都命令你要

@echo off 
for /f "delims=" %%a in (work.txt) do (
    set NUM=%%a 
) 

if %NUM%==1 goto start 
echo incorrect 
goto close 

:start 
start "Youtube playlist" "https://www.youtube.com" 
echo 2 > work.txt 
exit 

:close 
start "imager" "https://imgur.com/" 
echo 1 > work.txt 
exit 
+0

对修改目录属性不是很有帮助... – Stephan 2016-07-22 20:06:25