First instance of drive with free space

(imported topic written by jeko1791)

Hi,

I’m trying to determine what the drive letter is of the first non-system drive that has more than 2GB free disk space. I thought about checking D: then E: then F: but that seemed too rigid. Is there any other way to return the first instance only of a drive that meets these criteria?

This is what I have so far.

name of drive whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)

Obviously where this returns more than one drive, my action fails.

Thanks in advance,

(imported comment written by Lee Wei)

How about giving this a try:

(it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000))

I convert the drive letter to integer, so that we can pick the “minimum” value which translates to the first drive found, then convert back to the letter name.

However, if no drive is found, you will get an error. So here is another one with the if-then-else error check.

if (exists drive whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)) then ((it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000))) else (“None found”)

Lee Wei

(imported comment written by jeko1791)

Lee Wei,

Thank you. I think that is going to work exactly as we wanted.

(imported comment written by jeko1791)

Lee Wei,

This relevance clause is working on some systems but not others, and I cannot figure out what’s different between them. This is what we’re looking for, in order:

  • previous folder called out_dr on any drive to re-use as our OUT_DIR parameter
  • first available non-system drive with greater than 2GB free space to use as our OUT_DIR
  • system drive to use as our OUT_DIR

We’re embedding it into our Action Script as such:

if {exists folder “out_dr” of drives whose (type of it = “DRIVE_FIXED”)}

parameter “OUT_DIR”="{pathname of folder “out_dr” of drives whose (type of it = “DRIVE_FIXED”)}"

parameter “OUT_DIR_2K8”="{name of drive of folder “out_dr” of drives whose (type of it = “DRIVE_FIXED”)}"

elseif {exists drive whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)}

parameter “OUT_DIR”="{(it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)) & “\OUT_DR”}"

parameter “OUT_DIR_2K8”="{(it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000))}"

else if {exists drive whose (name of it = name of drive of system folder AND (free space of it / 1024 / 1024) as integer > 2000)}

parameter “OUT_DIR”="{name of drive of system folder & “\OUT_DR”}"

parameter “OUT_DIR_2K8”="{name of drive of system folder}"

endif

We’re getting a syntax error on some systems at this line after the first elseif:

parameter “OUT_DIR”="{(it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)) & “\OUT_DR”}"

It seems to be failing only on systems with several fixed disks with > 2GB free space. But, I’ve seen it work on other systems that have several non-system drives with > 2GB free space, so I’m not sure that’s why it’s failing.

Any ideas?

(imported comment written by Lee Wei)

I can’t spot anything obvious.

You have already checked that there is a drive with enough space:

exists drive whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)

Maybe return the names of the drives to see what is being returned:

names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)

If you can debug this locally on the problem computer, that is great. If you cannot, maybe try creating an analysis to include the different statements and see which one causes the problem.

  1. exists drive whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)

  2. names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)

  3. (it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000))

  4. (it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000)) & “\OUT_DR”

Lee Wei

(imported comment written by jeko1791)

Lee Wei,

I created the Analysis as you recommended. The systems that are returning the are returning True for exists fixed drive with >2GB free space (property 1 below). They return multiple drive names with the second property. Then return an with properties 3 and 4 below. Systems with a single drive and systems with no drives return acceptable values for properties 3 and 4.

That helped to clear it up. It does appear to be an issue with multiple results.

These two are producing errors:

(it & “:”) of hexadecimal string ((it as string) of minimum of ((preceding text of first “:” of it as hexadecimal) as integer) of names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000))

and the other one which is identical but adds the folder name to the end.

(imported comment written by Lee Wei)

Hi Jeff,

I found the problem and have to rewrite the entire relevance.

The problem is that when I convert the driver letters of hexadecimal, some of them, such as “Z” is hex 5A. This causes an error while converting to integer.

(preceding text of it & 
":\OUT_DR") of first 
";" of concatenations 
";" of unique values of (preceding text of first 
":" of it) of (names of drives whose (name of it != name of drive of system folder AND type of it = 
"DRIVE_FIXED" AND (free space of it / 1024 / 1024) as integer > 2000) )

The progression for the statements are as follows:

// We start with a bunch of drives meeting our criteria

// This is equivalent to the output from (names of drives whose (name of it != name of drive of system folder AND type of it = “DRIVE_FIXED” AND (free space of it / 1024 / 1024) as integer > 2000))

q: (“M:”; “R:”; “Z:”; “B:”)

A: M:

A: R:

A: Z:

A: B:

// Unique values have the effect of sorting the items in alphabetical order

q: unique values of (preceding text of first “:” of it) of (“M:”; “R:”; “Z:”; “B:”)

A: B

A: M

A: R

A: Z

// What we want is the first row. However, there is no operator in relevance to take the first row. So we string them together and take the first item

q: preceding text of first “;” of concatenations “;” of unique values of (preceding text of first “:” of it) of (“M:”; “R:”; “Z:”; “B:”)

A: B

// Final form

q: (preceding text of it & “:\OUT_DR”) of first “;” of concatenations “;” of unique values of (preceding text of first “:” of it) of (“M:”; “R:”; “Z:”; “B:”)

A: B:\OUT_DR

(imported comment written by jeko1791)

OK, now that this is working great for Windows, how would I do the same thing for Unix?

I want either:

a) to return the first partition that has at least 250MB free space

OR

b) return the first partition from the list below that has 250MB free space

/home

/tmp

/mksysb

I’ve started with b) and have this, but if the partition doesn’t exist, I get the “Nonexistent object” error:

if ((exists it and free space of (filesystem of it) > 256901120) of folder “/home”) then ("/home/tsm") else (if ((exists it and free space of (filesystem of it) > 256901120) of folder “/tmp”) then ("/tmp/tsm") else (if ((exists it and free space of (filesystem of it) > 256901120) of folder “/mksysb”) then ("/mksysb/tsm") else (nothings)))