Page 1 of 1 1
Topic Options
#19766 - 2002-04-12 12:23 AM Search in a dir and getting the last new file
Noisy Offline
Fresh Scripter

Registered: 2002-02-04
Posts: 6
I'm trying to let KIX search in a dir and getting the last sdat files in a variable

Dir:
sdat4194.exe
sdat4195.exe
Sdat4196.exe

So it has to search in the dir and come up with the Sdat4196.exe.

I have try searching the topic but didn't not find an example...can anyone help me please!

Thanks

Top
#19767 - 2002-04-11 01:12 PM Re: Search in a dir and getting the last new file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
do you then want the last by date or by that number in the name?
_________________________
!

download KiXnet

Top
#19768 - 2002-04-11 02:06 PM Re: Search in a dir and getting the last new file
Noisy Offline
Fresh Scripter

Registered: 2002-02-04
Posts: 6
I think it the best to get the numbers in the file
Top
#19769 - 2002-04-11 03:23 PM Re: Search in a dir and getting the last new file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if the format of the files is allways the same and no subfolders present, this will do:
code:
$filer=dir(my_folder_path)
do $file=$filer $filer=dir() $file ? until @error
? $file

I'll make you a better one in five minutes...
_________________________
!

download KiXnet

Top
#19770 - 2002-04-11 03:27 PM Re: Search in a dir and getting the last new file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Get the DIRPLUS(http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=12;t=000027) and BSORT(http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=12;t=000070) UDFs from the UDF section.

Read the appropriate list of files into an array so you end up with
code:
$filearray[0]='sdat4194.exe'
$filearray[1]='sdat4195.exe'

Then sort the array, by default the filename with the lowest number will be $filearray[0] and the filename with the highest number will be $filearray[ubound($filearray)]
code:
$filearray=dirplus('c:\temp','sdat*.exe')
$filearray=bsort($filearray)
$newestfile=$filearray[ubound($filearray)]



[ 11 April 2002, 15:27: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#19771 - 2002-04-11 03:33 PM Re: Search in a dir and getting the last new file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, it's done.

code:
$filer=dir(your_sdat_folder) $file="sdat0000.exe"
do
if "sdat"=substr($filer,1,4) and val(substr($filer,5,4))>val(substr($file,5,4))
$file=$filer
endif
$filer=dir()
until @error
? $file
get $

prints you the file.
_________________________
!

download KiXnet

Top
#19772 - 2002-04-11 03:35 PM Re: Search in a dir and getting the last new file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
to add to comments,
this assumes your files are of shape:
sdat****.exe

and that they reside in same folder.
other files and folders are ignored.
tested to be functional.

cheers,
_________________________
!

download KiXnet

Top
#19773 - 2002-04-11 04:54 PM Re: Search in a dir and getting the last new file
Noisy Offline
Fresh Scripter

Registered: 2002-02-04
Posts: 6
Then this has to work...Right!!??!!

First look in the dir en pick the last Sdat file
then compare this with the value in the reg
if its the same then do nothing and if not then update...

$regPath="HKEY_LOCAL_MACHINE\SOFTWARE\"
$SdatPath="\\server\McAfee\"
$Sdat="sdat0000.exe"

$filer=dir($SdatPath + "SuperDAT\")
do
if "sdat"=substr($filer,1,4) and val(substr($filer,5,4))>val(substr($Sdat,5,4))
$Sdat=$filer
endif
$filer=dir()
until @error

$sDATVer=SUBSTR($Sdat,5,4)
$VS45DATValue = READVALUE($RegPath + "McAfee\VirusScan","szVirDefVer")
$VS45DATNum = SUBSTR($VS45DATValue,5,4)

IF VAL($sDATVer) > VAL($VS45DATNum)
GOTO "SuperDAT"
ELSE
GOTO "END"
ENDIF

:SuperDAT
RUN ($SdatPath + "SuperDAT\" + $sDAT + " /silent /prompt")
GOTO "END"

:END

[ 11 April 2002, 17:14: Message edited by: Noisy ]

Top
#19774 - 2002-04-11 05:09 PM Re: Search in a dir and getting the last new file
Rocco Capra Offline
Hey THIS is FUN
*****

Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
I see what you are doing!! Your updateing Virus Definitions. I do the same thing but with Norton.

I have a script that checks an ftp site for a new file every night if it finds one it moves the current local file to an 'OLD' directory and downloads the new one. So there is only one file in the update directory. ( on the logon server )

The next thing is in the login I check to see if the update file = a log file on the locl PC, if it don't, I execute the update and create a new log file with the current update file name.

If you want to see the scripts just reply and I will post them or email then if you prefer.

Rocco
_________________________
I Love this board!! -------------------- My DEV PC is running KIX 4.22 WINXP Pro

Top
#19775 - 2002-04-12 08:48 AM Re: Search in a dir and getting the last new file
Noisy Offline
Fresh Scripter

Registered: 2002-02-04
Posts: 6
@sealeopard
Thanks for the reply

@Lonkero
It is working and thanks for helping me out!

@Rocco Capra
Yes i would like to see that script!

Top
#19776 - 2002-04-12 05:29 PM Re: Search in a dir and getting the last new file
Rocco Capra Offline
Hey THIS is FUN
*****

Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
Noisy,

Check your email.

Rocco
_________________________
I Love this board!! -------------------- My DEV PC is running KIX 4.22 WINXP Pro

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 641 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.061 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org