-5

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);
}
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
Helper Smith
  • 31
  • 1
  • 5
  • 2
    _"How can I encrypt only the files that are under 1 GB of size?"_ -- um, look at the size first and don't encrypt the file if it's smaller than your minimum? What have you tried? Your question is way too broad, and shows no evidence whatsoever that you've tried _anything_. – Peter Duniho Aug 29 '17 at 04:38

3 Answers3

0

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.

Nico
  • 12,493
  • 5
  • 42
  • 62
0

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);
}
Ali Adlavaran
  • 3,697
  • 2
  • 23
  • 47
0

Something like this should work:

foreach(string file in files)
{
    FileInfo fi = new FileInfo(file);
    if (fi.Length < 1073741824)
        EncryptFile(file, password);
}
blitz_jones
  • 1,048
  • 2
  • 10
  • 22