It's a simple question seeking a simple answer
How can I encrypt only the files that are under 1 GB of size?
I call my encrypt method with this code
foreach(string file in files)
{
EncryptFile(file, password);
}
It's a simple question seeking a simple answer
How can I encrypt only the files that are under 1 GB of size?
I call my encrypt method with this code
foreach(string file in files)
{
EncryptFile(file, password);
}
The simple answer.
foreach(var file in files)
{
if(File.Exists(file) && new FileInfo(file).Length < 1073741824) //1073741824 = 1GB
{
EncryptFile(file, password);
}
}
The explanation.
Check that the file exists, next use the FileInfo
class to get the Length
of the file (size) in bytes. Next check to ensure its less than 1GB 1073741824 bytes.
Use System.IO.FileInfo
. So try this:
foreach(string file in files)
{
var length = new System.IO.FileInfo(file).Length;
if (length < 1073741824)
EncryptFile(file, password);
}
Something like this should work:
foreach(string file in files)
{
FileInfo fi = new FileInfo(file);
if (fi.Length < 1073741824)
EncryptFile(file, password);
}