Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i need a batch file that checks the attribute date from several xls files. When the date is today it has to open another xls file. When it is not today do nothing.
This batch file must check the folder ACALL and ZCALL every 15 minutes.

:: process only today's files@echo off > %TEMP%\#
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir /s/b %TEMP%\#') do (
set mydate=%%~Ta
)for /f "tokens=1 delims= " %%a in (' echo !mydate!' ) do (
set today=%%a
)for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set TD=%%~Ta
for /f "tokens=1 delims= " %%a in ('echo !TD!') do (
set filedate=%%a
)
if !filedate! equ !today! echo process %%a
)
=====================================
If at first you don't succeed, you're about average.M2

thanks for youre quick reaction. Fot so far it works. But can you help me further because i am totally new to this.
The exact problem is;
I need a batch file that runs every 15 min, and then checks the c:\ACALLA, c:\ACALLF and c:\ZCALLZ folder for new files with the date of today. When they arrive in this folder the batch file has to open another xls file c:\excel\splitsing.xls. This excel file has an auto_macro in it..

I'll get back to you.
=====================================
If at first you don't succeed, you're about average.M2

Write a batch file to do just one iteration of the task. Then run this batch file every 15 minutes by using the Windows XP Task Scheduler. Alternatively, have a batch file that calls this one in a loop (with a suitable .exe utility that provides a delay.)
The batch file (which should be run every 15 minutes) is below.
@echo off
setlocal EnableDelayedExpansion
set new_file=
for %%f in (C:\ACALLA\*.xls C:\ACALLF\*.xls C:\ZCALLZ\*.xls) do (
for /f "tokens=1" %%t in ("%%~Tf") do (
set filedate=%%t
)
if !filedate! == %DATE% (
rem echo New file added: %%f
set new_file=y
)
)
if defined new_file c:\excel\splitsing.xlsNote: the above batch file assumes that splitsing.xls will delete any new files every time it is run. If it doesn't, then the batch file will open the Excel file every time, because the files with today's date are still there. If you want to check only for *new* files, i.e. those that weren't there the last time the batch file was run, well then that's a completely different problem.

Or, even more consisely, the batch file can be done in a single line:
dir C:\ACALLA\*.xls C:\ACALLF\*.xls C:\ZCALLZ\*.xls | find "%DATE%" >nul && c:\excel\splitsing.xls

Hi Klint...
Thanks for the quick support.....
I want to check only for *new* files, i.e. those that weren't there the last time the batch file was run.
An other problem was that in both batches splitsing.xls was not started. The path was oke but i got the error "system cannot find the file specified"

Hi
> I want to check only for *new* files,
> i.e. those that weren't there the last
> time the batch file was run.Then the file's date and today's date are irrelevant. All you need to do is keep a list (somehow) of files already seen, and check for ones that haven't been seen yet. I'm not sure how to do this at present but I'll think about it.
> An other problem was that in both batches
> splitsing.xls was not started. The path
> was oke but i got the error "system
> cannot find the file specified"Do you mean "system cannot find the PATH specified?"
Do you also get this error when you type
c:\excel\splitsing.xls
at the command prompt? If so, then how do you know that the path is ok? If you type
dir c:\excel\splitsing.xls
is it listed there?

:: process only new files@echo off & if not exist %TEMP%\prev @echo off > %TEMP%\prev
setLocal EnableDelayedExpansion:loop
dir /b > %TEMP%\curr
for /f "tokens=* delims= " %%a in (%TEMP%\curr) do (
find "%%a" < %TEMP%\prev > nul
if errorlevel 1 echo process %%a
)
copy %TEMP%\curr %TEMP%\prev > nul
:: ping -n 1 -w 900000 0.0.0.0
:: goto :loop
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |