Computer Hope

Microsoft => Microsoft DOS => Topic started by: Blisk on February 10, 2019, 02:25:10 AM

Title: zero bytes files
Post by: Blisk on February 10, 2019, 02:25:10 AM
This one is for my job but I will not get paid for that but it will make my life a bit easier for me so I will pay from my money.
It is next thing, we have an old PC with some odl software on it. And that software stops to work every fev days or weeks. Nobody knows why and how.
So I made a script which check a presence of dat_9_2_2019_18_20.log file. If script finds out that file is 0 Size and it is present in folder c:\administrator\data\dat_9_2_2019_18_20.log than it send me an email so when I see email I go to basement and restart that old PC.
I asked my boss many times to buy new PC and new software but he refuse he said it is to expencive and this still works good and it is my job to go now or than to reset that pc.
So I get an idea.
I can run script by task scheduler to check if that file  dat_9_2_2019_18_20.log is present and its size is 0 bytes than it restart pc automatically.
Problem is that software did not stop to work everytime when one file with 0 bytes is present, but when fev of them are in that folder. Rebooting to often is not good, because it takes about 15-25 minutes to restart PC to  work again.
So I thought if I can have a script which will start in task scheduler every 30 minutes and check folder c:\administrator\data if there are for example 5 files  or more like these
dat_9_2_2019_18_50.log 0 bytes
dat_9_2_2019_19_30.log 0 bytes
dat_9_2_2019_20_43.log 0 bytes
dat_9_2_2019_22_10.log 0 bytes
dat_9_2_2019_23_25.log 0 bytes
and all of them are empty than pc will reboot automatically. But it can reboot only 3 times after that I get an email and script stops to reboot. until I check what is going on and delete counter.txt file where script write number 3 which stops script to reboot after 3 times do that.
I already have script to send an email but this counting zero bytes files and reboot, that I can't manage to work it out.
In folder c:\administrator\data\ there is about 300 files and most of them are fev Kb and some are 0 bytes, those 0 bytes I usually delete and it can be all deleted or moved to another folder after script reboot PC. But those files fev KB must stay. Problem I also see here when one file (dat_9_2_2019_23_25.log 0 bytes) and right next after that file is another full file (dat_9_2_2019_23_50.log 10Kb), than that 0 bytes file should be deleted and counter.txt put to zero 0, or deleted, to star all over again. Because that means software still works ok.
so how much for this script?
Title: Re: zero bytes files
Post by: Salmon Trout on February 10, 2019, 03:19:05 AM
1. You want to delete ALL dat*.log files that are zero bytes in size?
2. or wait until there are >= 5 such files?
3. From folder c:\administrator\data\ ?
4. You say you want to reset counter.txt to "zero 0". What does that mean? You want that exact text? The word zero, then a space, then a figure 0?
5. Where is counter.txt located?

6. A good question to ask - why are all these zero byte files being created? is this caused when the software stops for an unknown reason?

7. It is not clear if you want the PC to reboot after the deletions.





Title: Re: zero bytes files
Post by: Blisk on February 10, 2019, 03:29:06 AM
1. You want to delete ALL dat*.log files that are zero bytes in size? Yes deleted or moved to new folder, one or other, with PC reboot.
2. or wait until there are >= 5 such files?  yes soure it should wait, to count files and when 5 of them is one after another.
3. From folder c:\administrator\data\ ? yes
4. You say you want to reset counter.txt to "zero 0". What does that mean? You want that exact text? The word zero, then a space, then a figure 0? in file counter.txt script will write just a number how many times PC reboots and when find number 3 it stops to reboot. So when I delete file or change number 3 in 0 than script works again and reboot if find 5 files with 0 bytes
5. Where is counter.txt located? doesn't matter it can be in  c:\administrator

6. A good question to ask - why are all these zero byte files being created? is this caused when the software stops for an unknown reason?
yes I notice that when software stops to work all those dat****.log files are created one by another

7. It is not clear if you want the PC to reboot after the deletions. when there are 5 files with 0 bytes than files can be deleted and imediatelly after that PC reboots. It doesn't need to reboot and after that files are deleted it can be deleted with rebooting.
Title: Re: zero bytes files
Post by: Salmon Trout on February 10, 2019, 05:02:09 AM
and when 5 of them is one after another.

This means what?
Title: Re: zero bytes files
Post by: Blisk on February 10, 2019, 06:10:41 AM
This means what?

it means 5 files are created one by another with zero bytes, like this
dat_9_2_2019_18_50.log 0 bytes
dat_9_2_2019_19_30.log 0 bytes
dat_9_2_2019_20_43.log 0 bytes
dat_9_2_2019_22_10.log 0 bytes
dat_9_2_2019_23_25.log 0 bytes

 that 5 files are deleted PC should reboot after that and counter will have number 1 in counter.txt

dat_10_2_2019_00_50.log 0 bytes
dat_10_2_2019_01_30.log 0 bytes
dat_10_2_2019_02_43.log 0 bytes
dat_10_2_2019_03_10.log 0 bytes
dat_10_2_2019_04_25.log 0 bytes

 that 5 files are deleted PC should reboot after that and counter will have number 2 in counter.txt

dat_10_2_2019_05_50.log 0 bytes
dat_10_2_2019_06_30.log 0 bytes
dat_10_2_2019_06_43.log 0 bytes
dat_10_2_2019_08_10.log 0 bytes
dat_10_2_2019_09_25.log 0 bytes

 that 5 files are deleted PC should reboot after that and counter will have number 3 in counter.txt
I get an email that something is wrong and script stop to reboot PC until I delete counter.txt or change number 3 in it to 0

it can be situation like this one
dat_5_2_2019_18_50.log 10 Kbytes
dat_5_2_2019_19_30.log 0 Kbytes
dat_5_2_2019_20_43.log 10 Kbytes
dat_5_2_2019_22_10.log 0 bytes
dat_5_2_2019_23_25.log 8 Kbytes

Files with 0 bytes should be deleted and counter.txt should have 0 in it

or like this one
dat_4_2_2019_18_50.log 10 Kbytes
dat_4_2_2019_19_30.log 11 Kbytes
dat_4_2_2019_20_43.log 10 Kbytes
dat_4_2_2019_22_10.log 0 bytes
dat_4_2_2019_23_25.log 8 Kbytes

File with 0 bytes should be deleted and counter.txt should have 0 in it

Title: Re: zero bytes files
Post by: Salmon Trout on February 10, 2019, 06:23:53 AM
But, logically any five files, listed in time order, will be "created one after another".
Title: Re: zero bytes files
Post by: Blisk on February 10, 2019, 06:27:08 AM
But, logically any five files, listed in time order, will be "created one after another".
Every new file is created about every ~45 minutes from last created file
and yes you are right
Title: Re: zero bytes files
Post by: Salmon Trout on February 10, 2019, 06:59:46 AM
Your comments please:

So this is what you want?

1. Before the first run, create counter.txt and write the value 0 in it.

2. Every 30 minutes the batch will
a.   Look at folder: c:\administrator\data\
   Count how many files are 0 bytes with this name pattern:

   dat_d_m_yyyy_hh_mm.log

   NOTE: the file name changes in number of characters, if day or month is greater than 9?

   So we just use file mask dat_*.log

   Is that OK?

b.   if there are fewer than 5, just delete them, leave counter alone.
   if there are 5 or more, delete them, add 1 to counter, save to counter.txt,
   if new number is 3, something is wrong, send email (how?????)
   if new number is 1,2, or 3, reboot computer.
   if number is greater than 3, do not reboot computer, you will manually reset after reading email.


Title: Re: zero bytes files
Post by: Blisk on February 10, 2019, 07:15:24 AM
Your comments please:

So this is what you want?

1. Before the first run, create counter.txt and write the value 0 in it.

2. Every 30 minutes the batch will
a.   Look at folder: c:\administrator\data\
   Count how many files are 0 bytes with this name pattern:

   dat_d_m_yyyy_hh_mm.log

   NOTE: the file name changes in number of characters, if day or month is greater than 9?

   So we just use file mask dat_*.log

   Is that OK? That is exactly what is should be.

b.   if there are fewer than 5, just delete them, leave counter alone. OK
   if there are 5 or more, delete them, add 1 to counter, save to counter.txt, OK
   if new number is 3, something is wrong, send email (how?????)

bmail -s mail.myserver.com -f [email protected] -t [email protected] -h -a "Check PC software may not be working" -b "" -m .\path.txt

   if new number is 1,2, or 3, reboot computer. OK
   if number is greater than 3, do not reboot computer, you will manually reset after reading email.
and delete counter.txt or change number from 3 to 0


Bmail (https://nextcloud.povej.net/index.php/s/eQJxAFPfeD9Dnkp)
Title: Re: zero bytes files
Post by: Salmon Trout on February 10, 2019, 02:17:04 PM
I have made a script which generates a logfile, I have tried it (manually not scheduled) with 0, then 3, then 5,5,5 zero byte files. It is still rough, but you can see what it does. You will not really see "Script exit" after "Rebooting computer" because the reboot will exit the script. If the script starts and finds the counter is 3 it just exits, (because you saw the email last time, and are coming to fix).

I will just show the logfile now, tell me what you think.

10/02/2019 21:07:30.38 Started script 
10/02/2019 21:07:30.40 Count read from file: 0 
10/02/2019 21:07:30.60 Zero size files: 0
10/02/2019 21:07:30.60 Script exit
**************************************
10/02/2019 21:07:51.28 Started script 
10/02/2019 21:07:51.30 Count read from file: 0 
10/02/2019 21:07:51.47 Zero size files: 3
10/02/2019 21:07:51.63 0 bytes dat_2019_02_10_21_07_39.log
10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_40.log
10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_42.log
10/02/2019 21:07:51.66 Deleting 3 0 byte files
10/02/2019 21:07:51.82 Rebooting computer
10/02/2019 21:07:51.83 Script exit
**************************************
10/02/2019 21:08:20.46 Started script 
10/02/2019 21:08:20.47 Count read from file: 0 
10/02/2019 21:08:20.71 Zero size files: 5
10/02/2019 21:08:20.88 0 bytes dat_2019_02_10_21_07_58.log
10/02/2019 21:08:20.89 0 bytes dat_2019_02_10_21_08_00.log
10/02/2019 21:08:20.91 0 bytes dat_2019_02_10_21_08_01.log
10/02/2019 21:08:20.92 0 bytes dat_2019_02_10_21_08_02.log
10/02/2019 21:08:20.94 0 bytes dat_2019_02_10_21_08_03.log
10/02/2019 21:08:20.97 Deleting 5 0 byte files
10/02/2019 21:08:21.16 Found 5 or more files
10/02/2019 21:08:21.17 Count increased to 1
10/02/2019 21:08:21.21 Rebooting computer
10/02/2019 21:08:21.22 Script exit
**************************************
10/02/2019 21:08:46.24 Started script 
10/02/2019 21:08:46.27 Count read from file: 1 
10/02/2019 21:08:46.46 Zero size files: 5
10/02/2019 21:08:46.63 0 bytes dat_2019_02_10_21_08_30.log
10/02/2019 21:08:46.65 0 bytes dat_2019_02_10_21_08_32.log
10/02/2019 21:08:46.66 0 bytes dat_2019_02_10_21_08_33.log
10/02/2019 21:08:46.68 0 bytes dat_2019_02_10_21_08_34.log
10/02/2019 21:08:46.69 0 bytes dat_2019_02_10_21_08_35.log
10/02/2019 21:08:46.72 Deleting 5 0 byte files
10/02/2019 21:08:46.93 Found 5 or more files
10/02/2019 21:08:46.94 Count increased to 2
10/02/2019 21:08:46.96 Rebooting computer
10/02/2019 21:08:46.99 Script exit
**************************************
10/02/2019 21:09:12.14 Started script 
10/02/2019 21:09:12.14 Count read from file: 2 
10/02/2019 21:09:12.34 Zero size files: 5
10/02/2019 21:09:12.53 0 bytes dat_2019_02_10_21_08_56.log
10/02/2019 21:09:12.54 0 bytes dat_2019_02_10_21_08_57.log
10/02/2019 21:09:12.56 0 bytes dat_2019_02_10_21_08_58.log
10/02/2019 21:09:12.57 0 bytes dat_2019_02_10_21_09_00.log
10/02/2019 21:09:12.59 0 bytes dat_2019_02_10_21_09_01.log
10/02/2019 21:09:12.61 Deleting 5 0 byte files
10/02/2019 21:09:12.79 Found 5 or more files
10/02/2019 21:09:12.81 Count increased to 3
10/02/2019 21:09:12.82 Sending email
10/02/2019 21:09:12.86 Script exit
**************************************
10/02/2019 21:20:22.67 Started script
10/02/2019 21:20:22.67 Count read from file: 3
10/02/2019 21:20:22.70 Counter was 3 or more
10/02/2019 21:20:22.73 Script exit
**************************************
Title: Re: zero bytes files
Post by: Blisk on February 11, 2019, 02:20:01 AM
this one will be good only in this situation
10/02/2019 21:07:51.28 Started script
10/02/2019 21:07:51.30 Count read from file: 0
10/02/2019 21:07:51.47 Zero size files: 3
10/02/2019 21:07:51.63 0 bytes dat_2019_02_10_21_07_39.log
10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_40.log
10/02/2019 21:07:51.64 100 bytes dat_2019_02_10_21_07_41.log
10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_42.log
10/02/2019 21:07:51.66 Deleting 3 0 byte files
10/02/2019 21:07:51.82 not Rebooting computer
10/02/2019 21:07:51.83 Script exit

in this case
10/02/2019 21:07:51.28 Started script
10/02/2019 21:07:51.30 Count read from file: 0
10/02/2019 21:07:51.47 Zero size files: 3
10/02/2019 21:07:51.63 0 bytes dat_2019_02_10_21_07_39.log
10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_40.log
10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_42.log
10/02/2019 21:07:51.66 not Deleting 3 0 byte files
10/02/2019 21:07:51.82 not Rebooting computer
10/02/2019 21:07:51.83 Script exit

script should leave zero bytes files and next time it runs if there is more zero files like this than it delete and reboot.

10/02/2019 21:08:20.46 Started script
10/02/2019 21:08:20.47 Count read from file: 0
10/02/2019 21:08:20.71 Zero size files: 5
10/02/2019 21:08:20.88 0 bytes dat_2019_02_10_21_07_58.log
10/02/2019 21:08:20.89 0 bytes dat_2019_02_10_21_08_00.log
10/02/2019 21:08:20.91 0 bytes dat_2019_02_10_21_08_01.log
10/02/2019 21:08:20.92 0 bytes dat_2019_02_10_21_08_02.log
10/02/2019 21:08:20.94 0 bytes dat_2019_02_10_21_08_03.log
10/02/2019 21:08:20.97 Deleting 5 0 byte files
10/02/2019 21:08:21.16 Found 5 or more files
10/02/2019 21:08:21.17 Count increased to 1
10/02/2019 21:08:21.21 Rebooting computer
10/02/2019 21:08:21.22 Script exit

if script find only 3 zero bytes files than it should leave it so next time it runs if there is 5 files of zero bytes than reboot computer, but if one of last 5 files is full and is not empty than it should delete zero bytes files and reset counter to 0
Title: Re: zero bytes files
Post by: Salmon Trout on February 12, 2019, 01:47:10 PM
counter = 0
no zero byte files


12/02/2019 20:23:13.24 Started script
12/02/2019 20:23:13.26 Count read from file: 0
12/02/2019 20:23:13.46 Zero size files: 0
12/02/2019 20:23:13.49 No 0 bytes files found; exiting
12/02/2019 20:23:13.52 Script exit
**************************************


Counter = 0
3 zero byte files


12/02/2019 20:28:45.94 Started script
12/02/2019 20:28:45.97 Count read from file: 1
12/02/2019 20:28:46.16 Zero size files: 3
12/02/2019 20:28:46.33 0 bytes dat_2019_02_12_20_28_38.log
12/02/2019 20:28:46.34 0 bytes dat_2019_02_12_20_28_39.log
12/02/2019 20:28:46.37 0 bytes dat_2019_02_12_20_28_40.log
12/02/2019 20:28:46.39 Fewer than 5 0 bytes files; exiting
12/02/2019 20:28:46.41 Script exit
**************************************


Counter = 0
6 zero byte files (repeated)


12/02/2019 20:32:23.08 Started script
12/02/2019 20:32:23.12 Count read from file: 0
12/02/2019 20:32:23.34 Zero size files: 6
12/02/2019 20:32:23.53 0 bytes dat_2019_02_12_20_30_43.log
12/02/2019 20:32:23.55 0 bytes dat_2019_02_12_20_30_44.log
12/02/2019 20:32:23.56 0 bytes dat_2019_02_12_20_30_46.log
12/02/2019 20:32:23.58 0 bytes dat_2019_02_12_20_30_47.log
12/02/2019 20:32:23.61 0 bytes dat_2019_02_12_20_30_48.log
12/02/2019 20:32:23.62 0 bytes dat_2019_02_12_20_30_49.log
12/02/2019 20:32:23.64 Found 5 or more files
12/02/2019 20:32:23.66 Count increased to 1
12/02/2019 20:32:23.69 Deleting 6 0 byte files
12/02/2019 20:32:23.92 Rebooting computer
12/02/2019 20:32:23.94 Script exit
**************************************


12/02/2019 20:33:40.52 Started script
12/02/2019 20:33:40.55 Count read from file: 1
12/02/2019 20:33:40.75 Zero size files: 6
12/02/2019 20:33:40.94 0 bytes dat_2019_02_12_20_33_24.log
12/02/2019 20:33:40.95 0 bytes dat_2019_02_12_20_33_25.log
12/02/2019 20:33:40.97 0 bytes dat_2019_02_12_20_33_26.log
12/02/2019 20:33:40.98 0 bytes dat_2019_02_12_20_33_27.log
12/02/2019 20:33:41.00 0 bytes dat_2019_02_12_20_33_29.log
12/02/2019 20:33:41.03 0 bytes dat_2019_02_12_20_33_30.log
12/02/2019 20:33:41.05 Found 5 or more files
12/02/2019 20:33:41.06 Count increased to 2
12/02/2019 20:33:41.09 Deleting 6 0 byte files
12/02/2019 20:33:41.30 Rebooting computer
12/02/2019 20:33:41.31 Script exit
**************************************


12/02/2019 20:43:01.70 Started script
12/02/2019 20:43:01.73 Count read from file: 2
12/02/2019 20:43:01.97 Zero size files: 6
12/02/2019 20:43:02.16 0 bytes dat_2019_02_12_20_35_34.log
12/02/2019 20:43:02.17 0 bytes dat_2019_02_12_20_35_36.log
12/02/2019 20:43:02.19 0 bytes dat_2019_02_12_20_35_37.log
12/02/2019 20:43:02.20 0 bytes dat_2019_02_12_20_35_38.log
12/02/2019 20:43:02.23 0 bytes dat_2019_02_12_20_35_39.log
12/02/2019 20:43:02.25 0 bytes dat_2019_02_12_20_35_41.log
12/02/2019 20:43:02.26 Found 5 or more files
12/02/2019 20:43:02.28 Count increased to 3
12/02/2019 20:43:02.31 Deleting 6 0 byte files
12/02/2019 20:43:02.51 Sending email
12/02/2019 20:43:02.55 Script exit
**************************************


12/02/2019 20:44:23.95 Started script
12/02/2019 20:44:24.01 Count read from file: 4
12/02/2019 20:44:24.04 Counter was 3 or more
12/02/2019 20:44:24.04 Script exit
**************************************








Title: Re: zero bytes files
Post by: Blisk on February 12, 2019, 01:54:29 PM
Script looking verry good but What happends in this case?

12/02/2019 20:43:01.70 Started script
12/02/2019 20:43:01.73 Count read from file: 2
12/02/2019 20:43:01.97 Zero size files: 6
12/02/2019 20:43:02.16 0 bytes dat_2019_02_12_20_35_34.log
12/02/2019 20:43:02.17 0 bytes dat_2019_02_12_20_35_36.log
12/02/2019 20:43:02.19 0 bytes dat_2019_02_12_20_35_37.log
12/02/2019 20:43:02.20 0 bytes dat_2019_02_12_20_35_38.log
12/02/2019 20:43:02.23 10 Kbytes dat_2019_02_12_20_35_39.log
12/02/2019 20:43:02.25 0 bytes dat_2019_02_12_20_35_41.log
12/02/2019 20:43:02.26 Found 5 or more files
12/02/2019 20:43:02.28 Count increased to 3
12/02/2019 20:43:02.31 Deleting 6 0 byte files
12/02/2019 20:43:02.51 Sending email
12/02/2019 20:43:02.55 Script exit
Title: Re: zero bytes files
Post by: Salmon Trout on February 12, 2019, 02:06:05 PM
In that case, the 5 zero bytes files are deleted, the count is increased to 3, the email is sent, computer is not restarted.

What did you want to happen?

In all of these tests these files are also there, they are ignored.

10/02/2019  20:12                37 dat_2019_02_10_20_12_16.log
10/02/2019  20:12                37 dat_2019_02_10_20_12_17.log
10/02/2019  20:12                37 dat_2019_02_10_20_12_18.log
10/02/2019  20:12                37 dat_2019_02_10_20_12_20.log
Title: Re: zero bytes files
Post by: Salmon Trout on February 12, 2019, 02:13:17 PM
To be clear, the script only counts the files that are 0 bytes. All other files with size larger than 0 are not counted or processed, and their presence or absence does not trigger any actions.
Title: Re: zero bytes files
Post by: Blisk on February 12, 2019, 02:50:20 PM
Problem is because sometimes I get 2 files with zero bytes and next one is like 10Kb.
in this case it means software still works and I don't need to reboot PC.
so when that happend script should only delete all zero bytes files and leave counter at zero
Title: Re: zero bytes files
Post by: Salmon Trout on February 12, 2019, 02:59:37 PM
What do you mean 'next one'?
Title: Re: zero bytes files
Post by: Blisk on February 12, 2019, 03:04:58 PM
like this
12/02/2019 20:43:02.16 0 bytes dat_2019_02_12_20_35_34.log
12/02/2019 20:43:02.17 0 bytes dat_2019_02_12_20_35_36.log
12/02/2019 20:43:02.19 0 bytes dat_2019_02_12_20_35_37.log
12/02/2019 20:43:02.20 0 bytes dat_2019_02_12_20_35_38.log
12/02/2019 20:43:02.23 10 Kbytes dat_2019_02_12_20_35_39.log
Title: Re: zero bytes files
Post by: Salmon Trout on February 12, 2019, 03:36:07 PM
So now the script must analyse all files, and if there is a nonzero size file next after a zero size file, then do nothing? This is too complex for batch. Sorry.
Title: Re: zero bytes files
Post by: Blisk on February 13, 2019, 12:40:40 AM
So now the script must analyse all files, and if there is a nonzero size file next after a zero size file, then do nothing? This is too complex for batch. Sorry.

Ok than please do it only with zero bytes files that will still make easier for me. Like you show me your logs
I will go down sometimes with false flag but still better than everytime when software stops to work.
Title: Re: zero bytes files
Post by: Salmon Trout on February 13, 2019, 12:58:41 AM
If you have some zero byte files, and a later nonzero, and then later zero size files, what then?
Title: Re: zero bytes files
Post by: Blisk on February 13, 2019, 01:11:23 AM
If you have some zero byte files, and a later nonzero, and then later zero size files, what then?
nothing leave until last 5 files are zero, than delete all zero bytes files and reboot
Title: Re: zero bytes files
Post by: Salmon Trout on February 13, 2019, 01:37:40 PM
Is the folder full of files? What if there are 100 files?
Title: Re: zero bytes files
Post by: Blisk on February 13, 2019, 03:01:22 PM
Is the folder full of files? What if there are 100 files?

yes there is about 100 files.
I have an idea how to solve this I will try with my lame knowledge, to solve this with script, I will be glad if you improve it.
I will try something and if it works I will paste it here.
Title: Re: zero bytes files
Post by: Salmon Trout on February 14, 2019, 12:00:30 PM
So, really, we need to put the files in date/time order, from first to last, and look at the last 5 files? If there are less than 5 zero size files among these, do nothing. If there are 5 (all of the last 5 files are zero size), delete all zero size files, add 1 to counter, and reboot? Repeat until counter = 3, then send email? This is not so hard and I know a way with VBS that is simple.
Title: Re: zero bytes files
Post by: Squashman on February 14, 2019, 04:15:14 PM
I have an idea how to solve this I will try with my lame knowledge, to solve this with script, I will be glad if you improve it.
I will try something and if it works I will paste it here.
I don't know to many people who increase their knowledge without trying to solve a problem. If a teacher just gave you the answers, you would learn nothing.
Title: Re: zero bytes files
Post by: patio on February 14, 2019, 05:30:18 PM
+ 1 + 1
Title: Re: zero bytes files
Post by: Blisk on February 18, 2019, 05:00:47 AM
Ok I finally have time to complete this, I think this is a script which works, I tested it and it works.
I know it should be better written but this is as far as I know to do it
I be glad if Salmon improve it.

Code: [Select]
findstr /m "3" reboot_times.txt
IF ERRORLEVEL 1 (goto H) else (goto End)
:H
pushd .\data
mkdir check

for /f "tokens=1,* delims=:" %%a in ('dir /o-d /a-d-h /b * ^| findstr /n "^"') do (
    if %%a gtr 5 goto done
    copy /y "%%b" .\check
)
:done
popd
pushd .\data\check
@echo off
SET COUNTER=0
FOR /f "delims=" %%i IN ('dir /o:-d /b') do (
  if %%~zi EQU 0 (
    DEL /q "%%i"
    SET /A COUNTER+=1
  )
)
for /r %%F in (*) do if %%~zF==0 del "%%F"

popd

rmdir /q /s .\data\check

echo %COUNTER% > null.txt


findstr /m "5" null.txt
IF ERRORLEVEL 1 (goto End) else (goto Z)
:Z
for /r %%F in (*) do if %%~zF==0 del "%%F"
if exist "reboot_times.txt" (goto A1) else (goto B1)
:B1
copy /y nul reboot_times.txt
@echo 0 > reboot_times.txt
:A1
for /f "tokens=* delims=" %%x in (reboot_times.txt) do (
  set /a var=%%x+1
)
@echo %var% > reboot_times.txt
set "var=%var*=%"
rem shutdown -r -f
:End
del /Q /F null.txt