Avatar of earngreen
earngreenFlag for United States of America

asked on 

Looping Batch file

I am looking for a batch file that loops through over and over again until it finds a file that has been created with a todayand if the file is found then it creates a new text file, if not it continues to loop. Any ideas?
Windows Batch

Avatar of undefined
Last Comment
sirbounty
Avatar of sirbounty
sirbounty
Flag of United States of America image

This may work...

for /r c:\ %%a in (.) do (
if not /i [%done%]==[y] call :process %%~ta
)
goto :eof

:process
set dt=%1
if [%dt%]==[%date%] (
copy %0 c:\created.txt
set done=y
)
Avatar of earngreen
earngreen
Flag of United States of America image

ASKER

Please comment code, I am not sure what some of this is doing
Avatar of sirbounty
sirbounty
Flag of United States of America image

for /r is a loop through all subfolders recursively, so by stating to start at c:\, it'll scan all folders on that drive.
If the variable %done% is not set to 'y', then it'll end the script, otherwise, it jumps to the process sub passing the date of the file(s) found.

if the date value of that file is the same as the current date value, then it creates a text file and flags done = 'y'. and thus the script ends.

Only caveat is that if your date is displaying the day as well..

Try
echo %date%
from a command line.
If it has the day preceeding the date, this will need to be adjusted a bit:

if [%dt%]==[%date:~4%] (

(just that line though)
Avatar of earngreen
earngreen
Flag of United States of America image

ASKER

The date displays the day. So I made the change as you suggested with no results.
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of earngreen
earngreen
Flag of United States of America image

ASKER

Here are the results.

[]==[y] was unexpected at this time.

C:\>if not /i []==[y] call :process %~ta
Avatar of sirbounty
sirbounty
Flag of United States of America image

transposed the parameter...should be

if /i not...instead of if not /i
Windows Batch
Windows Batch

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

13K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo