取消隐藏usb文件批处理命令

时间:2015-08-03 07:16:25

标签: windows batch-file

我在Windows 8.1上。我用隐藏文件/文件夹获取USB。要取消隐藏它们,我使用attrib命令。我想通过简单地插入USB来运行命令。帮助。

echo off
echo Please have patience!!!  Wait or Minimise the window!!!

rem c:\script\unhide.bat 
@echo off

for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype 2^>NUL`) do (

if %%l equ 2 (
echo %%i is a USB drive.
        )
        )
Pause

这里我收到了驱动器号H.我无法使用驱动器号并在USB中使用以下命令。我怎么能在USB下面的命令下面运行。我的意思是Change Drive,在USB中运行attrib命令,从USB中删除不需要的文件并查看USB的内容。

cd\
attrib -s -h -r /s /d
del *.lnk
del thumbs.db
del desktop.ini
del autorun.inf
echo Your Folders has been recovered!!!  Check your folders and files
dir
pause
exit

1 个答案:

答案 0 :(得分:0)

@ECHO OFF
SETLOCAL enableextensions
echo Please have patience!!!  Wait or Minimise the window!!!
rem c:\script\unhide.bat 
for /F "skip=1 tokens=1-3" %%i in ('
  wmic logicaldisk where "drivetype=2" get caption^,drivetype^,SystemName
  ') do (
  if "%%j"=="2" (
    echo "%%i" is a USB drive ^(DriveType=%%j^).
    pushd "%%i\"
      SETLOCAL enabledelayedexpansion
        echo current folder !CD!
      ENDLOCAL
      echo attrib -H -S -T /S /D /L >NUL 2>&1
      echo del *.lnk       2>NUL
      echo del thumbs.db   2>NUL
      echo del desktop.ini 2>NUL
      echo del autorun.inf 2>NUL
      echo Your Folders has been recovered!!!  Check your folders and files
      dir
      pause
    popd
  )
)
ENDLOCAL
goto :eof

注意:

  • wmic命令更改如下:
    • where条款;
    • description省略,因为此属性的字数不同,因此会中断标记化;
    • 始终附加非空属性SystemName以传递返回行中的结尾回车符wmic behavior =每个输出行以0x0D0D0A结尾(<CR><CR><LF>)而非公共0x0D0A<CR><LF>)。对于另一种(一般)方法,请参阅Dave Benham&#39; WMIC and FOR /F: A fix for the trailing <CR> problem;
  • for /F循环根据更改的wmic命令(和skip=1)进行调整;
  • 操作attrib -H -S -T /S /D /L仅用于echo以进行调试;除了调试之外删除echo(所有del命令都相同);
  • 使用pushd - popd对:PUSHD changes the current directory/folder and stores the previous folder/path for use by the POPD command;
  • 文件夹System Volume Information应保留属性System&amp; Hidden如果有的话。