Computing.Net > Forums > Programming > Batch file to check file attribute

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to check file attribute

Reply to Message Icon

Name: tonyol
Date: January 29, 2008 at 04:20:22 Pacific
OS: WinXP
CPU/Ram: T7250 2GHZ
Product: Intel
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 29, 2008 at 04:28:09 Pacific
Reply:


:: process only today's files

@echo off > %TEMP%\#
setLocal EnableDelayedExpansion

for /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



0

Response Number 2
Name: tonyol
Date: January 29, 2008 at 04:51:10 Pacific
Reply:

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..


0

Response Number 3
Name: Mechanix2Go
Date: January 29, 2008 at 05:27:50 Pacific
Reply:

I'll get back to you.



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: klint
Date: January 29, 2008 at 09:35:13 Pacific
Reply:

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.xls

Note: 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.


0

Response Number 5
Name: klint
Date: January 29, 2008 at 09:46:13 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: tonyol
Date: January 30, 2008 at 02:37:08 Pacific
Reply:

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"


0

Response Number 7
Name: klint
Date: January 30, 2008 at 03:56:52 Pacific
Reply:

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?


0

Response Number 8
Name: Mechanix2Go
Date: January 31, 2008 at 06:39:12 Pacific
Reply:


:: 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



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to check file attribute

how to check batch file www.computing.net/answers/programming/how-to-check-batch-file/2856.html

batch file to check modified date www.computing.net/answers/programming/batch-file-to-check-modified-date/12915.html

Batch file to check for .exe file www.computing.net/answers/programming/batch-file-to-check-for-exe-file/16163.html