skip to Main Content
[1:2:4]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (5).zip: Filesize,11624
[1:2:4]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (3) (2) (2).zip: Filesize,0
[1:2:4]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (6).zip: Filesize,11624
[1:2:5]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (3) (2) (3).zip: Filesize,8164795
[1:2:5]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (3) (3).zip: Filesize,8164795
[1:2:8]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (7).zip: Filesize,8164795
[1:2:9]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (8).zip: Filesize,26625
[1:2:11]:C:UsersAdministratorDesktopTELEGRAM.SECOND.STAGEUploads (9).zip: Filesize,11624

libary: using myoddweb.directorywatcher;

my File im watching gets downloaded automatically by Telegram, but its not catching tHe Filesize all the times, it sometimes displays 0.

Can someone help me to fix this problem? Im currently using this Code:

// create Watcher
var watcher = new Watcher();
watcher.Add(new Request(path_desktop + "\TELEGRAM.SECOND.STAGE", true));
watcher.Start();
watcher.OnAddedAsync += async (f, t) =>
{
    FileInfo x = new FileInfo(f.FileSystemInfo.FullName);
    long filesize = x.Length;
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine($"[{f.DateTimeUtc.Hour}:{f.DateTimeUtc.Minute}:{f.DateTimeUtc.Second}]:{f.FileSystemInfo.FullName}: Filesize,{filesize}");
};
Console.ReadKey();

i did try everything no chance

2

Answers


  1. You are only looking at a single option for files.. Take a look at the link below.

    https://learn.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher?view=net-7.0

    There are more options such as created, changed, deleted, etc and even a Notification Filter. Hopefully these extra parts may help you, especially if you the OnChanged…

    Login or Signup to reply.
  2. i hope this help you it’s unit with the size of the file

            var unit = new string[] { "B", "KB", "MB", "GB", "TB" };
    
            var size = file.Length;
    
            var sizeWithUnit = 1024 < size ? (
                size < 1000000 ? ((double)(size / 1024)).ToString("0.##") + unit[1] : 
                1000000 < size && size < 1000000000 ? ((double)(size / 1024) / 1024).ToString("0.##") + unit[2] :
                (((double)(size / 1024) / 1024) / 1024).ToString("0.##") + unit[3]
                ) :
                unit[0];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search