FileList revisited and a note on scientific notation

Hello,

To prevent data loss, my program MCMusiceditor (https://www.mcmusiceditor.com) saves song codes to a backup directory. Over time, this backup directory becomes very large. Such disk consuming behaviour can be inconvenient. MCMusiceditor has no function that signals a warning message if the backup directory exceeds some size limit. So I decided to make a directory size function for the next release. Sorry, my function is not spectacular at all. However, it has two things, I’ll like to share with you.

1. My post on FileList (https://visualneo.com/visualneo-win/fileexists-has-a-wonderful-alternative) did not contain a section on the pipe character | (#124). It’s useful for creating match options. Example: to generate a list of all files with different extensions, you could write

FileList "[directory-to-scan]\*.txt|*.bak|*.odt" "" "[mc-files]"

To generate list of all files with specific filenames, you could write

FileList "[directory-to-scan]\*05062020.*|*07062020.*" "" "[mc-files]"

which is the same as

FileList "[directory-to-scan]\*[#91]05062020-07062020[#93].*" "" "[mc-files]"

2. I wasn’t aware of the fact that VisualNeo recognizes scientific notation.

SetVar "[unit-data-storage]" "1.024e+3"

which evaluates like SetVar “[unit-data-storage]” “2^10” to SetVar “[unit-data-storage]” “1024”

Notice that math functions can be used in SetVar (https://visualneo.com/visualneo-win/math-expressions-in-control-commands). If you do not want evaluation of math expressions, use ! as a prefix. Example: SetVar “[unit-data-storage]” “!2^10”. Here 2^10 is taken literally and not evaluated to 1024.

Below my directory size function. I hope it’s useful for you.

Best regards,
Reinier

....................................................................................................
.Objective 1: determine the size of a directory
.Objective 2: determine the size of specific files in a directory
....................................................................................................
SetVar "[directory-to-scan]" "[PubDir]backup"
....................................................................................................
.Objective 1
....................................................................................................
.Generate a list of all files, extension inclusive (folders excluded)
FileList "[directory-to-scan]\*.*" "" "[mc-files]"
......................................................................................................
......................................................................................................
.Objective 2
................................................................................
.Generate list of all files with specific extensions,
.extension inclusive (folders excluded)

FileList "[directory-to-scan]\*.txt|*.bak" "" "[mc-files]"

.Generate list of all files with specific filename,
.extension inclusive (folders excluded)
.FileList "[directory-to-scan]\*05062020.*|*07062020.*" "" "[mc-files]"

.which is the same as
.FileList "[directory-to-scan]\*[#91]05062020-07062020[#93].*" "" "[mc-files]"
.....................................................................................................................................

.Separate the string [mc-files] into multiple parts using the delimiter character [#13]
StrParse "[mc-files]" "[#13]" "[mc-filenames]" "[no-mc-filenames]"

.Optional: initialize the variable used for summing up all filesizes
SetVar "[directory-size-in-bytes]" "0"

.Determine the sum total of the filesizes in [directory-to-scan]
Loop "1" "[no-mc-filenames]" "[i]"
  FileSize "[directory-to-scan]\[mc-filenames[i]]" "[file-size]"
  Math "[directory-size-in-bytes]+[file-size]" "0" "[directory-size-in-bytes]"
EndLoop

..........................................................................................
.Express [directory-size-in-bytes] into B, KB, MB or GB
..........................................................................................
SetVar "[units-of-memory-0]" "B"
SetVar "[units-of-memory-1]" "KB"
SetVar "[units-of-memory-2]" "MB"
SetVar "[units-of-memory-3]" "GB"

.1 KB = 1024 B
.1 MB = 1024 KB = 1024^2 B
.1 GB = 1024 MB = 1024^3 B

.SetVar "[unit-data-storage]" "1024"

.is the same as

.SetVar "[unit-data-storage]" "2^10"

.is the same as (because VisualNeo recognizes scientific notation)
SetVar "[unit-data-storage]" "1.024e+3"

If "[directory-size-in-bytes]" "=" "0"
  Alertbox "Result" "Directory: [directory-to-scan]||Number of files: [no-mc-filenames]||Size: [directory-size-in-bytes] [units-of-memory-0]"
Else
  Loop "3" "0" "[i]"
   If "[directory-size-in-bytes]" ">=" "[unit-data-storage]^[i]"
    Math "[directory-size-in-bytes]/[unit-data-storage]^[i]" "0" "[directory-size]"
    Alertbox "Result" "Directory: [directory-to-scan]||Number of files: [no-mc-filenames]||Size: [directory-size] [units-of-memory-[i]]"
    ExitLoop
   EndIf
  EndLoop
EndIf