Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically Delete Files/Folders

Is there any way to automatically delete all files or folders with few R command lines? I am aware of the unlink() or file.remove() functions, but for those you need to define a character vector with exactly all the names of the files you want to delete. I am looking more for something that lists all the files or folders within a specific path (e.g. 'C:/Temp') and then delete all files with a certain name (regardless of its extension).

Any help is very much appreciated!

like image 652
Francesco Avatar asked Feb 15 '12 15:02

Francesco


People also ask

Can Windows automatically delete files?

Storage Sense in Windows 10 is a new feature. When you enable it, Windows will automatically delete unused files when the computer is low on disk space. For instance, it can automatically delete files older than 30 or 60 days from the Recycle Bin or delete temporary files to free up some space.

How do I schedule a deletion file?

Use this command: ForFiles /p “C:\path\to\folder” /s /d -30 /c “cmd /c del /q @file”. Change “30” for the number of days you want and the folder path.

How do I fix Windows 10 automatically delete files?

Step 1: In the “Settings,” go to “System” and look for the “storage” option. Step 2: The “Storage Sense” option is “On” by default. Turn it off so that Windows 10 doesn't delete any of the files from recycle bin or downloads folder automatically.

Why are my files automatically deleted?

Windows Storage Sense feature: The main reason for this problem is due to a newer feature of Windows called "Storage Sense". If you turn on this feature, it will automatically delete unused files and temporary files when your computer is running low on disk space.


2 Answers

Maybe you're just looking for a combination of file.remove and list.files? Maybe something like:

do.call(file.remove, list(list.files("C:/Temp", full.names = TRUE))) 

And I guess you can filter the list of files down to those whose names match a certain pattern using grep or grepl, no?

like image 152
joran Avatar answered Sep 22 '22 19:09

joran


For all files in a known path you can:

unlink("path/*") 
like image 33
Hahnemann Avatar answered Sep 26 '22 19:09

Hahnemann