Delete file contents every 24 hours

cesario678

Client
Регистрация
10.03.2022
Сообщения
130
Благодарностей
10
Баллы
18
"Is there a way for the bot to delete the contents of a file every 24 hours, and if it hasn't been 24 hours, it checks and doesn't delete the file's content? Is this possible, and if so, how can I do it?"
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
When you create a file, add DateTime in filename. And when you take a file check filename and compare if it's older than 24h.
 
  • Спасибо
Реакции: cesario678

cesario678

Client
Регистрация
10.03.2022
Сообщения
130
Благодарностей
10
Баллы
18
Ao criar um arquivo, adicione DateTime no nome do arquivo. E quando você pega um arquivo, verifique o nome do arquivo e compare se ele tem mais de 24h.
[/CITAR]
Não entendi essa segunda parte. Como alguém criaria uma função que compara e verifica se já se passaram mais de 24 horas? Você poderia me explicar mais claramente?"
I didn't understand this second part. How would one create a function that compares and checks if it has been more than 24 hours? Could you explain it to me more clearly?"
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
Thats the logic to achieve what you asked. When you create this file you give it a name with Date and Time in a file-name.
Then with every next run you take this filename, and you have a starting date.
Then you get Date Time NOW and you have actual date time.
Difference between those date times will be your required value, more or less than 24 hours.

Try searching forum for "DateTime " to find lots of C# snippets to make your life much easier.
 
  • Спасибо
Реакции: cesario678

cesario678

Client
Регистрация
10.03.2022
Сообщения
130
Благодарностей
10
Баллы
18
So I researched, didn't see anything that fits, I understood what you said well, I just didn't understand the last part. What function would I have to use for it to analyze and see that the current day has more than 24 hours than the file name
 

myndeswx

Client
Регистрация
15.05.2017
Сообщения
411
Благодарностей
93
Баллы
28
You can use UNIX time, it's made exactly for tasks like this one, that way you can delete it correctly after exactly 24 hours not a minute more or less =)
 

Вложения

  • Спасибо
Реакции: cesario678

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)