-2

We have requirement wants to ensure whether file name start with 1a.xxxx_py.csv and 1a.xxxxx_CY.csv files are exist from folder. If files are exist will do further steps else send notification email to business stating that required files does not exist.

Note-File name should not be hardcoded

Please let me know any possibilities in PowerShell scripts or batch scripts? Please share the scripts.

  • Welcome to SO. This is a forum where coders voluntarily help other coders with their challenges. ;-) There are some rules and best practices helping you to get the most out of SO. First you may take the [Tour] to get an overview and then you may stop by on [ask]. To make it easier for others willing to help you to actually help you you should always [format your code](https://stackoverflow.com/help/formatting) properly and provide a [mre]. ;-) Have a nice day! – Olaf Aug 30 '23 at 07:02
  • Please open a command prompt window, run `help` and look on the incomplete list of [Windows commands](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) with brief description. The command required is __IF__. Run next `if /?` and read the output usage help carefully and completely. A batch file with the line `if not exist "C:\Folder Path\1a.*_py.csv" if not exist "C:\Folder Path\1a.*_CY.csv" echo Folder "C:\Folder Path" does not exist or contains no file matched by 1a.*_py.csv or 1a.*_CY.csv& pause & exit /B` is something you can start with. – Mofi Aug 30 '23 at 13:48
  • Run in the command prompt window also `echo /?` and `pause /?` and `exit /?` for the output of the short helps of the three additional commands. See also [single line with multiple commands using Windows batch file](https://stackoverflow.com/a/25344009/3074564) for an explanation of the unconditional command operator `&` used here to run in total three commands if the two conditions evaluate both with true (file not exist). – Mofi Aug 30 '23 at 13:49
  • Or if there should be checked for the existence of a file `1a.*_CY.csv` for each `1a.*_py.csv` in a folder, there can be used a batch file with `for %%G in ("C:\Folder Path\1a.*_py.csv") do for /F "eol=| delims=_" %%H in ("%%~nG") do if not exist "%%~dpG%%H_CY%%~xG" echo Missing file: "%%~dpG%%H_CY%%~xG"`. It is of course also possible with a few small modifications to search for `1a.*_CY.csv` and check the existence of appropriate `1a.*_py.csv` file. Run `for /?` in the command prompt window and read entirely its long help. – Mofi Aug 30 '23 at 13:49

0 Answers0