,你可以這樣做
if not exists %directory%\%file%
這樣你創建一個完整的文件路徑,如 「C:\ MyFolder文件\ yourfolder \ myfile.txt的」,並檢查它的存在
更新
這應該工作(但它未測試)
:: starting folder
set RootPath=c:\myfolder\yourfolder\
::check all subfolder
for /R "%RootPath%" %%d IN (.) DO (
echo %%d
:: check all file in each subfolder
for %%f IN ("%%~d\*.*") DO (
:: check if your file exist
IF "%%~nxf"=="filenameImLookingFor.txt" (
echo Found file here "%%~f"
)
)
)
- %%〜NXF將拓展與延伸FILNAME,沒有路徑
- 的「〜」同時也要確保擴大的變量都不會包含 前綴/後綴doublequte,這樣您就可以添加自己的無需意想不到的雙重雙引號 (這將明顯地搞搞 高達)
這裏是一個變量有用的命令的列表(從的幫助下FOR命令)
您現在可以使用下列選項語法:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
的修飾符可以結合使用來得到多重結果:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
來源
2012-05-10 09:14:47
Max
是的,但該文件可能是在子目錄,一路下來的樹。 – rsk82
@ rs82 - 你知道它應該在哪個目錄下,或者你想知道它是否位於指定目錄下的任何位置? – jeb
任何地方。 – rsk82