'Batch: Using the find command when path contains wildcards

I have a file structure that looks like this:

%~dp0 > %USER% > %DATE1%_%USER%.csv

where I am using SET /P to create the USER & DATE1 variables.

I have a few queries set up to count the number of lines in the .csv files:

:QUERY0
ECHO Searching for %USER% on %DATE1% . . .
FIND /C /V "" "%~dp0%USER%\%DATE1%_%USER%.csv" >> "%~dp0%DATE1%_%USER%_Report.txt" && (ECHO. & ECHO %DATE1%_%USER%_Report.txt Created)
"%~dp0%DATE1%_%USER%_Report.txt"
EXIT

:QUERY1
ECHO Searching for  + ANY USER +  on %DATE1% . . .
FIND /C /V "" "%~dp0*\%DATE1%_*.csv" >> "%~dp0%DATE1%_Report.txt" && (ECHO. & ECHO %DATE1%_Report.txt Created)
"%~dp0%DATE1%_Report.txt"
EXIT

:QUERY2
ECHO Searching for %USER% on  + ANY DATE + . . .
FIND /C /V "" "%~dp0%USER%\*_%USER%.csv" >> "%~dp0%USER%_Report.txt" && (ECHO. & ECHO %USER%_Report.txt Created)
"%~dp0%USER%_Report.txt"
EXIT

Queries "0" and "2" work like a dream, but I cannot figure out how to get "1" to work. Is there a way to get FIND to use a path with wildcards in it?



Solution 1:[1]

I have come up with a solution. It may not be the most elegant, but it works for this scenario.

:QUERY1
ECHO Searching for  + ANY USER +  on %DATE1% . . .
IF EXIST "%~dp0Userlist.txt" (DEL "%~dp0Userlist.txt")
DIR "%~DP0" /A:D /B > "%~dp0Userlist.txt"
FOR /F usebackq^ skip^=1^ delims^=^ eol^= %%L in ("%~dp0Userlist.txt") do (FIND /C /V "" "%~dp0%%L\%DATE1%_%%L.csv" >> "%~dp0_Reports\%DATE1%_Report.txt")
IF EXIST "%~dp0Userlist.txt" (DEL "%~dp0Userlist.txt")
"%~dp0_Reports\%DATE1%_Report.txt"
EXIT

I am using the DIR to create a list of all of the folders in %~dp0 which is the usernames I am looking for, and then using some code I borrowed from a different source to read the .txt file output of DIR with the FOR command so that I can assign the lines in the .txt file to an arbitrary %%L variable to use in the file path.

Solution 2:[2]

function myfunk() {
  const GOOGLE_SHEET_NAME = "FormData";
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  ['id1', 'id2'].forEach(GOOGLE_FORM_ID => {
    const [header, ...data] = ss
      .getSheetByName(GOOGLE_SHEET_NAME)
      .getDataRange()
      .getDisplayValues();
    const choices = {};
    header.forEach((title, i) => {
      choices[title] = data.map((d) => d[i]).filter((e) => e);
    });

    FormApp.openById(GOOGLE_FORM_ID)
      .getItems()
      .map((item) => ({
        item,
        values: choices[item.getTitle()],
      }))
      .filter(({ values }) => values)
      .forEach(({ item, values }) => {
        switch (item.getType()) {
          case FormApp.ItemType.CHECKBOX:
            item.asCheckboxItem().setChoiceValues(values);
            break;
          case FormApp.ItemType.LIST:
            item.asListItem().setChoiceValues(values);
            break;
          case FormApp.ItemType.MULTIPLE_CHOICE:
            item.asMultipleChoiceItem().setChoiceValues(values);
            break;
          default:
          // ignore item
        }
      });
  });
  ss.toast("Google Forms Updated !!");
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BlinkingJaguar
Solution 2 Cooper