简体   繁体   中英

Batch Script to display the filenames with extension (.skc) in mail body or at least put the .skc values in a variable from @file

I am still stuck with this. Can anyone of you please help me out to figure out how to achieve this.

First of all, thanks for all your help!

I am in need of a batch script which need to do the following.

  1. Suppose a path is there (D:\\test)
  2. Script should go to the above path and search for text files as in ( D:\\test*.skc)
  3. If .skc files are found. It should trigger a mail where all the .skc files should be mentioned in the mail body.
  4. This should be running all the time like daemons and trigger the mail only if .skc is found.

Please help me achieving this.

I tried doing something from my end, where i am able to put the .skc files in a log file. but getting results as expected above.

please find my work below.

 @echo off set file_path="D:\\test" forfiles /d -0 /p %file_path% /m *.skc /c "cmd /c echo @file" >> "D:\\test\\example.log" 

Or at-least please help me get the following.

The below batch script which will pull out all the files with extension .skc from a specific path and all this will be written in @file as below.

forfiles /d -0 /p %file_path% /m *.skc /c "cmd /c echo @file"

I need to put this @file in a variable, like

output=@file
echo %output%

Can you please help me achieve this?

@ECHO OFF
SETLOCAL
SET "logfiledir=u:\destdir"
SET "monitordir=u:\destdir"
ECHO(skc files report>"%logfiledir%\log.1"
SET /a nextlog=0
:monitor
SET /a prevlog=1-nextlog
ECHO(skc files report>"%logfiledir%\log.%nextlog%"
dir /b /a-d "%monitordir%\test*.skc" >>"%logfiledir%\log.%nextlog%" 2>NUL
FINDSTR /v /g:"%logfiledir%\log.%prevlog%" ".skc" "%logfiledir%\log.%nextlog%" >NUL 2>nul
IF NOT ERRORLEVEL 1 (
 ECHO(CALL BLAT using "%logfiledir%\log.%nextlog%"
)
SET /a nextlog=(nextlog + 1) %% 2
timeout /t 2 >nul
GOTO monitor

Hmm - interesting exercise.

This batch allows you to set up the directory to keep thisbatch 's logfiles and the directory to monitor separately.

It maintains files log.1 and log.0 and looks for changes.

First step is to create a dummy previous-log file with a set string and then establish which is the next logfile to use.

Within the loop, we derive the previous logfile name and generate a new version of the current logfile with our set string

append to the current logfile a /b (bare - names only) /ad (and no directorynames) directory list of the directory to monitor.

Find whether there are any lines in the new file that are not in the old (setting errorlevel 0 if so, non-zero if not)

Invoke the email if there were new entries. I use blat - you pays your money, you takes your choice...

Then change the next logfile identity

wait (I chose 2 seconds for testing) and repeat ad infinitum.

The problem with findstr is that it doesn't like an empty exclude file ( /g:... ) so identical strings need to be inserted into each log file as dummies.

Don't remove the timeout otherwise this procedure will become a processor-hog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM