Jump to content
Macro Express Forums

Retrieving Directory Size & Drive Free Space


eganopperman

Recommended Posts

I need to set the values of two Macro Express variables: one, with the amount of free space on my backup drive, and the other, with the file size of the subdirectory I wish to backup. I want the macro to evaluate the two values so that if the file size of the subdirectory is greater than than the free space on the backup drive a popup message is triggered directing the operator to replace the backup drive. Does anyone know of an eloquent way of retreiving such information? If I can get it into an ascii or text file I then can have Macro Express retrieve it and set the variables. TIA.

Link to comment
Share on other sites

Hello Egan!

 

Here is one solution ... although eloquent is in the eye of the beholder ;). This macro uses the O/S's DIR command to get the size of a disk drive and also the size of all files in a folder. Just change the variables to suit your situation. I have attached a playable mxe file.

// T1=Drive, T2=Output file, T3=Output folder, T4=Input folder
Variable Set String %T1% "c:\"
Variable Set String %T2% "FreeSpace.txt"
Variable Set String %T3% "c:\Temp"
Variable Set String %T4% "c:\Pgm3"

// If output file exists then ersae it
If File Exists "%T2%"
 Delete File or Files: "%T2%"
End If

// Get the drive free space
Program Launch: "cmd"
Wait for File Exist: "%T2%"
Wait for File Ready: "%T2%"

// Scan for the "bytes free" line
Text File Begin Process: "%T2%"
 If Variable %T5% contains "bytes free"
   Break
 End If
Text File End Process

// Extract the drive size to D1
Replace "bytes free" with "" in %T5%
Variable Modify String: Trim %T5%
Variable Set Integer %N1% from Position of Text in Variable %T5%
Variable Modify String: Delete Part of %T5%
Variable Modify String: Trim %T5%
Variable Modify String: Convert %T5% to decimal %D1%

// Now get the sizes of the files within the input folder
Delete File or Files: "%T2%"
Program Launch: "cmd"
Wait for File Exist: "%T2%"
Wait for File Ready: "%T2%"

// Scan for the "bytes free" line. Save the line number
Variable Set Integer %N1% to 0
Text File Begin Process: "%T2%"
 Variable Modify Integer: Inc (%N1%)
 If Variable %T5% contains "bytes free"
   Break
 End If
Text File End Process

// Extract the folder size to D2
Variable Modify Integer: Dec (%N1%)
Text File Begin Process: "%T2%"
Text File End Process
Replace "bytes" with "" in %T5%
Variable Modify String: Trim %T5%
Variable Set Integer %N1% from Position of Text in Variable %T5%
Variable Modify String: Delete Part of %T5%
Variable Modify String: Trim %T5%
Variable Modify String: Convert %T5% to decimal %D2%
Macro Return

DriveAndFolderSizes.zip

Link to comment
Share on other sites

  • 11 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...