How can I test if a list of files exist?

后端 未结 6 2148
花落未央
花落未央 2021-02-15 18:25

I have a file that lists filenames, each on it\'s own line, and I want to test if each exists in a particular directory. For example, some sample lines of the file might be

6条回答
  •  滥情空心
    2021-02-15 19:27

    In Windows:

    
    type file.txt >NUL 2>NUL
    if ERRORLEVEL 1 then echo "file doesn't exist"
    

    (This may not be the best way to do it; it is a way I know of; see also http://blogs.msdn.com/oldnewthing/archive/2008/09/26/8965755.aspx)

    In Bash:

    
    if ( test -e file.txt ); then echo "file exists"; fi
    

提交回复
热议问题