WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Secondlaw on September 19, 2014, 01:48:51 PM

Title: Drive space percentage etc...
Post by: Secondlaw on September 19, 2014, 01:48:51 PM
I have a bunch of directories under 1 sub directory.  Is there an easy way to determine the drive space percentage and remove files in each of those directories that are older than xx days (input when script runs).

While trying to get the drive space percentage, I'm using this:


MyDriveTotal=DiskSize(UNC,1)
MyDriveFree=DiskFree (UNC,1)

PercentageFree=(MyDrivefree/MyDriveTotal *100) but it isn't returning what I'm expecting (xx.xxxx)... It's returning (-xxxxx)

Thanks for your help.


Title: Re: Drive space percentage etc...
Post by: td on September 21, 2014, 09:32:36 AM
If you want to do math with 'huge numbers' you will need to do with the 'huge number' extender.  Otherwise, you should just  use the default floating point format (0) because you can use floating point math.  Floating point math does not require an extender.
Title: Re: Drive space percentage etc...
Post by: Secondlaw on September 22, 2014, 07:58:52 AM
Very helpful, thanks.  I used the extender and retrieved exactly what I was looking for. 

Is there a way to use the TimeDate function to compare the difference in days of an actual file date?

Timedate reports | Mon 9/22/2014 10:52:59 AM

Using Fileinfotoarray, I'm able to get all of the info I need from all of the files in a directory but the dates are reported differently:
2014:08:18:05:55:32

I guess I can parse all of this info and do some math for year differences and day differences but there has to be an easier way.

***EDIT***  Ok, hold off on this.  I think I found the timediff function.  :)

Title: Re: Drive space percentage etc...
Post by: Secondlaw on September 23, 2014, 05:30:53 AM
It's been a while since using winbatch but I still love the flexibility.

So this seems to do exactly what I need which is...  if a drive has under a certain percentage of free space, delete all files in each sub-directory that are more than xxx days old.  If the sub-directory is empty, just delete it.

AddExtender("WWHUG44I.DLL", 0, "WWHUG64I.DLL")

date=TimeYmdHms()
year=itemExtract(1,Date,":")

GetDir = DirScript()
Purger=strcat(getDir, "Purger.ini")

DriveSpacepercentage = IniReadPvt ("Settings", "Percentage", "", purger)
DaysToPurge          = IniReadPvt ("Settings", "DaysToPurge", "", purger)
UNC                  = IniReadPvt ("Settings", "PurgePath", "", purger)

SubDirs=strcat(UNC, "\","*.*")

infoarray = DirInfoToArray(SubDirs, 1|2)

MyDriveTotal=DiskSize(UNC,1)
MyDriveFree=DiskFree (UNC,1)

PercentagefreeD=huge_divide(MyDriveFree,MyDriveTotal)
Percentagefree =huge_multiply(PercentagefreeD,100)

If  DriveSpacePercentage < Percentagefree

For xx = 1 To Infoarray[0,0]
  Dirinfostr = strcat(infoarray[xx,0])

  infostrfiles = strcat(Dirinfostr, "\*.*")
  infolistfiles= Fileinfotoarray(infostrfiles, 1|2)
 
  If (infolistfiles[0,1]) <1
   dirRemove(DirInfoStr)
   else
   GOSUB DeleteFiles
  endif
next

:DeleteFiles
For aa = 1 to infolistfiles[0,0]
   FileInfoName = strcat (infolistfiles[aa,0])
   FileInfoDate = strcat (infolistfiles[aa,2])
   DateDiff=timediffdays(date, fileInfoDate)
   If DateDiff > DaysToPurge
    FileDelete (FileInfoName)
   endif
next

return

EndIf ;endif for percentagefree.

exit


If there was an easier way, I'd love to see it.  This is working fine for me but maybe next time I'll try something different.