How to write a batch file to delete folders and files in time?

Exact duplicates:

I want to write a batch file to delete folders, subfolders and temporary files in time.

The conditions are as follows:

  • I need to delete a file from a folder an hour before the current time.
  • I want to get the current time from the system and delete an hour before the files
  • The file format is as follows: <file name> <date>
  • Time format dd-mm-yyyy-hh-mmordd-mm-yy-hh-mm
+2
source share
2 answers

A package can be surprisingly powerful, but I don’t think the kind of date manipulation you want will be practical.

You can use FORto separate the date in the elements, and then use SET /Ato perform subtraction, but then you need a great number of operators IFand GOTOfor handling cases such as subtracting a half hour midnight on January 1st.

I think you better research VBS or Powershell .

+2
source

You might want to try this script to delete files from a folder older than 1 hour.

# Script Delete1Hour.txt
var str folder, list, file
cd $folder
lf -n "*" $folder ($ftype=="f") AND ( $fmtime < addtime(diff("-10000")) ) > $list
while ($list <> "")
do
    lex "1" $list > $file
    system del ("\""+$file+"\"")
done

biterscripting.

lf -n "*" $folder ($ftype=="f") AND ( $fmtime < addtime(diff("-10000")) )

biterscripting - $folder , "*", "f" ( , ) ($ fmtime) 1 . . lf http://www.biterscripting.com/helppages/lf.html.

script C:/Scripts/Delete1Hour.txt,

script  "C:/Scripts/Delete1Hour.txt" folder("C:/testfolder")

C:/testfolder, 1 .

+1

Source: https://habr.com/ru/post/1704256/


All Articles