#130669 - 2004-12-06 04:26 PM
Scanning sub folders
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
Does anyone have an exmaple of how to check and scan files inside a master folder to al scan and show the files in all sub folders that are within that master folder???
|
|
Top
|
|
|
|
#130671 - 2004-12-06 04:30 PM
Re: Scanning sub folders
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
|
|
Top
|
|
|
|
#130672 - 2004-12-06 04:34 PM
Re: Scanning sub folders
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
Ahhh excellent! Thank you. and also thank you Bryce Lindsay
|
|
Top
|
|
|
|
#130674 - 2004-12-06 11:09 PM
Re: Scanning sub folders
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
OK I hit a snag, and maybe just maybe you can help.
The dirplus code works great, but I wanted to do based on a date range of old than X days.
Using the function SerialDate I am able to scan files based on a single folder, but how would I use both dirplus and SerialDate together to look for files and sub folder files within a date frame.
|
|
Top
|
|
|
|
#130676 - 2004-12-06 11:28 PM
Re: Scanning sub folders
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
OK here we go.
I will try to paint the picture for you as best as I can.
An example would be a folder c:\data and within that folder are other sub folders.
Within each root folder and sub folders are files. Each files has been created and uploaded to the root folder and sub folders at different dates.
The goal I was hoping to get to was to run the kix to scan first the root and look for any files that are past 15 days old to delete, and then also scan all subfolder and delete any files in the sub folder that are past 15 days old.
The date would be based off of the modified date.
Using the UDF function SerialDate($ExpD) I was able to write this script.
Code:
cls
break on
$path = 'c:\data
$file = dir($Path + '\*')
GLOBAL $X
;used for days compare check
$days=15
$line =1
while $file <> "" and @error = 0
$ft = getfiletime($path + '\' + $file)
$fs = getfilesize($path + '\' + $file)
$size = $foo +','+ $bar
$store = substr($file,12,3)
if $ft ;it's a file not a dir !
; List the files
$file_date = substr($ft,1,10)
;used for looking for older files
$result=SerialDate(@date)
$result=$result-$days
$result=SerialDate($result)
if $file_date < $result
;? '$file $file_date'
$size = GetFileKB($path + "\" + $file)
$line=$line+1
;DELETE FILES
$foo = $path + "\" + $file
; REMARKED THE DEL OUT FOR TESTING
; del $foo
? $foo +" "+$file_date
endif
endif
$file = dir()
loop
$line=$line-1
But I cannot do the subfolders and looking at the dirplus UDF only got even more confused.
Do I even need dirplus? Can I just do this to sub folders also?
|
|
Top
|
|
|
|
#130677 - 2004-12-06 11:57 PM
Re: Scanning sub folders
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
here is a sample using 2 udf's DIRPlus() and FlipCTime()
Code:
$path = 'c:\temp'
$files = dirplus($path,"/s /a-d")
$15days = 60*60*24*15
for each $file in $files $filedate = split($file.DateLastModified) $filedate[0] = split($filedate[0],"/") if flipctime($filedate[0][2] + "/" + $filedate[0][1] + "/" + $filedate[0][0],$filedate[1]) <= flipctime(@date,@time)-$15days ? $file.name + " is 15+ days old: " + $file.DateLastModified endif next
|
|
Top
|
|
|
|
#130679 - 2004-12-07 12:18 AM
Re: Scanning sub folders
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
You may want to look at fnGetFolderProp() - Uses FSO to retrieve folder properties as well. It can display the DateLastModified property and can be used to created child collections for SubFolders and Files.
|
|
Top
|
|
|
|
#130681 - 2004-12-07 05:59 AM
Re: Scanning sub folders
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Quote:
Or look at CleanDirectory() as Les mentioned.
does that do subfolders?
|
|
Top
|
|
|
|
#130684 - 2004-12-07 05:37 PM
Re: Scanning sub folders
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
Excellent! very excited to try all these options out. You all are the best!
|
|
Top
|
|
|
|
#130685 - 2004-12-07 05:51 PM
Re: Scanning sub folders
|
Microcyb
Getting the hang of it
Registered: 2002-12-30
Posts: 95
Loc: Hell
|
Quote:
here is a sample using 2 udf's DIRPlus() and FlipCTime()
Code:
$path = 'c:\temp'
$files = dirplus($path,"/s /a-d")
$15days = 60*60*24*15
for each $file in $files $filedate = split($file.DateLastModified) $filedate[0] = split($filedate[0],"/") if flipctime($filedate[0][2] + "/" + $filedate[0][1] + "/" + $filedate[0][0],$filedate[1]) <= flipctime(@date,@time)-$15days ? $file.name + " is 15+ days old: " + $file.DateLastModified endif next
That worked like a charm! The one that uses CLEANDIRECTORY only did root folder.
But in short this has given me the direction I need.
Again you all are the best!!!
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 363 anonymous users online.
|
|
|