Get a folder path where is missing specified file into variable

点点圈 提交于 2019-12-11 17:58:12

问题


Let's say I have two folders in one.

MyFolder\Folder1\ - contains .class and .java file

MyFolder\Folder2\ - contains only .class file

The question is, if you can make the batch file detect the folder in (MyFolder) where is a .java file missing and put the path into a variable.

Something like:

find sub/folder with no *.java files in MyFolder\ <-and somehow to put the folder path into a variable

Does anyone know what would the script look like? Thanks to everybody that will help.


回答1:


Here is an idea, you can work on it to make it suit your needs:

Setlocal EnableDelayedExpansion
for /D %%f in (MyFolder\*) do if not exist %%f\*.java (
    set nonJavaFolder=%%f
)
echo !nonJavaFolder!



回答2:


@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir\t w o"
FOR /f "tokens=1*delims=" %%a IN (
  'dir /b /ad "%sourcedir%\*" '
  ) DO (
  IF NOT EXIST "%sourcedir%\%%a\*.java" ECHO no .java IN "%sourcedir%\%%a"
  IF NOT EXIST "%sourcedir%\%%a\*.class" ECHO no .class IN "%sourcedir%\%%a"
)

GOTO :EOF

You would need to change the setting of sourcedir to suit your circumstances.

Naturally, you could set a variable instead of echoing the result. You don't say what you want to do if there is more than one directory with missing files.



来源:https://stackoverflow.com/questions/28384875/get-a-folder-path-where-is-missing-specified-file-into-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!