1.

Solve : plz help me with batch file (check whether new file exists)?

Answer»

Hi,
I am new to Dos and need some help. I am searching some 15 files every 30 mins from 12.00am to 7.00am in schedule tasks. first time search is FINE..what ever the files EXISTS it will display but next time when i run, it should display only new files names.

eg: sun dir
1.txt
2.txt

when i run the script ,the o/p should be " found 2 files "

Now after 1 hr it has 4 file

1.txt
2.txt
3.txt
4.txt

when i run the script now, the o/p should be "found 2 files"

i.e IT SHOULD SEARCH FOR NEW FILES ONLY THOUGH THE OLD FILES EXISTS.

Plz help me..

Thanks in advance...

chinna

Perhaps a log file that says the files that were in there last time would be necessary?

I'll give it a shot.

Quote

@echo off

set indir=INPUT DIRECTORY

set log=%temp%\filelog.log
set /a newc=0
set /a oldc=0
set /a change=0

for /f "delims=" %%I in ('dir /b /a:-d "%indir%"') do (
set /a newc+=1
)

if exist "%log%" (
set /p oldc=<"%log%"
)

>"%log%" echo %newc%

set /a change=%newc%-%oldc%
echo There are %newc% files, %change% of them being additional since the last check.
pause >nul
here's a vbscript
Code: [Select]Option Explicit
Dim myFolderToSearch,myFile,FileName,OutFile
Dim objFSO,objFolder,objOutFile
Dim temp
myFolderToSearch = "c:\temp"
OutFile = "c:\test1\latest.txt"
Set objFSO=CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(OutFile) Then 'If the checking file does not exist, create
Set objOutFile = objFSO.CreateTextFile(OutFile,true)
objOutFile.Write "0"
objOutFile.Close
temp = 0
Else
Set objOutFile = objFSO.OpenTextFile(OutFile,1) 'read the file
temp = objOutFile.ReadLine 'get value of last date time stamp
objOutFile.Close
End If

For Each myFile In objFSO.GetFolder(myFolderToSearch).Files
If objFSO.GetExtensionName(myFile) = "txt" Then
If myFile.DateLastModified > CDate(temp) Then
temp=myFile.DateLastModified
FileName=myFile
WScript.Echo "FileName found: " & myFile & ", Time: " & temp
End If
End If
Next
Set objOutFile = objFSO.OpenTextFile(OutFile,2) 'write newest
objOutFile.Write temp
objOutFile.Close
Two options have been supplied, if possible could you tell us if the TASK has been overcome?Hi guys,
Thank you for your HARD work and helping me.. Its working perfect and once again you.

regards,
chinna


Discussion

No Comment Found