如何编写批处理文件以检查目录中的特定文件夹

时间:2013-11-25 17:30:52

标签: file batch-file

如何编写批处理文件以检查目录中的指定子文件夹,然后生成显示结果结果的日志文件(找到或未找到)。我是脚本的新手,下面是我到目前为止的内容:

@echo off
ECHO
SET /P QUESTION="Perform file check (Y/N)?"
if QUESTION == y goto :START_SCRIPT 

:START_SCRIPT
if exist "C:\Folder\ABC" (echo found it) else echo not found;

if exist "C:\Folder\DEF" (echo found it) else echo not found;

if exist "C:\Folder\GHI" (echo found it) else echo not found;

test.bat >> out.txt

3 个答案:

答案 0 :(得分:0)

很简单;

@echo off
choice /m "Perform Check?"
if errorlevel 2 Exit

:loop
set /p query="Folder Name: "
if "%query%"=="" goto :end
if exist "C:\Folder\%query%" (Echo %query% Exists&Echo %query% Found >> out.txt
) Else (
Echo %query% Doesn't Exist&Echo %query% Not Found >> out.txt
)
goto :loop
:end
Echo End of Batch File&sleep 5
Exit

这应该做你想要的(注意它需要用户输入),如果不是这样,可以使用重定向的日志文件作为输入。

莫纳

答案 1 :(得分:0)

我是这样做的:

@echo off
setlocal
cd /d %~dp0
call :FolderExists abc && Echo Yes || Echo No
exit /b

:FolderExists folder
for /f %%a in ('dir /b /ad') do (
  if /i %%a EQU %1 exit /b 0)
exit /b 1

答案 2 :(得分:0)

再一次

@echo off
    set "folder=c:\folder"

(   for %%d in ("ABC" "DEF" "GHI") do if exist "%folder%\%%~d" (
        echo "%%~d" found
    ) else (
        echo "%%~d" not found
    )
) >> file.log