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!
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.
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.
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.
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.
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?
For all files in a known path you can:
unlink("path/*")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With