Delete contents of a folder every night


Recommended Posts

there are several ways.

the way I would do it is set a task in task scheduler and either set the delete command right in the task or point the task to a batch file

  • Like 2

Off the top of my head, I'd probably create a batch script and put it into the task scheduler to run each night, maybe at 0300 or something.

I think the command would be:

cd C:\Users\James\AppData\Local\Plex Media Server\Cache\
rmdir /s /q PhotoTranscoder

 

On 08/02/2024 at 10:03, Nick H. said:

Off the top of my head, I'd probably create a batch script and put it into the task scheduler to run each night, maybe at 0300 or something.

I think the command would be:

cd C:\Users\James\AppData\Local\Plex Media Server\Cache\
rmdir /s /q PhotoTranscoder

 

technically don't even need the cd command; can just be a one line command. also would need "" around the directory path due to the spaces in the Plex Media Server folder.

rmdir /s /q "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder"

 

On 08/02/2024 at 08:07, Brandon H said:

technically don't even need the cd command; can just be a one line command. also would need "" around the directory path due to the spaces in the Plex Media Server folder.

rmdir /s /q "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder"

 

Thank you, what would be the command to just delete the contents of the folder instead of the folder itself ?

On 08/02/2024 at 11:09, jamester64 said:

Thank you, what would be the command to just delete the contents of the folder instead of the folder itself ?

I think a standard del command with a * wildcard should work

del /S /Q /F "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*"

 

On 08/02/2024 at 12:18, Brandon H said:

I think a standard del command with a * wildcard should work

del /S /Q /F "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*"

 

Please note, these "del" and "rmdir" commands will not work with powershell and will only work in the context of cmd.exe

 

If you are going to create a scheduled task for this and wish to use these CMD commands, you will need to create the "Action" as follows:

In the "Program/script" portion of adding a new "Start a program" action, you would put cmd.exe with the arguments /C "del /S /Q /F 'C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*"'

 

A functional scheduled task would look like this:

image.png.cca282ba8e80f86fac5d05c704697108.png

On 08/02/2024 at 09:18, Brandon H said:

I think a standard del command with a * wildcard should work

del /S /Q /F "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*"

 

That deleted the contents of the folders inside the directory but left the folders

Looking to delete the entire contents of this folder  C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder

On 08/02/2024 at 12:28, jamester64 said:

That deleted the contents of the folders inside the directory but left the folders

Looking to delete the entire contents of this folder  C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder

You can do this with Powershell and the "Remove-Item" command: 

remove-item c:\utils\test\* -recurse -force

If you wanted to bake it into a scheduled task, you can run powershell.exe with the -command argument like follows:

powershell.exe -command "remove-item c:\utils\test\* -recurse -force"

 

  • Like 2
  • Love 1
On 08/02/2024 at 11:28, jamester64 said:

That deleted the contents of the folders inside the directory but left the folders

Looking to delete the entire contents of this folder  C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder

yeah, bad limitation of the two commands. alternate option would be go back to previous command and just have a 2nd command to recreate the folder after I think

rmdir /s /q "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder"
mkdir "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder"

 

On 08/02/2024 at 11:32, satukoro said:

You can do this with Powershell and the "Remove-Item" command: 

remove-item c:\utils\test\* -recurse -force

 

also a good option. I'm still familiarizing myself with the PowerShell version of commands like that so didn't think of it.

On 08/02/2024 at 12:33, Brandon H said:

yeah, bad limitation of the two commands. alternate option would be go back to previous command and just have a 2nd command to recreate the folder after I think

rmdir /s /q "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder"
mkdir "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder"

also a good option. I'm still familiarizing myself with the PowerShell version of commands like that so didn't think of it.

I nearly posted the same solution of "make the directory after deleting it" but realized I had just done this in a .ps1 script I wrote for something random at my job.

On 08/02/2024 at 09:32, satukoro said:

You can do this with Powershell and the "Remove-Item" command: 

remove-item c:\utils\test\* -recurse -force

If you wanted to bake it into a scheduled task, you can run powershell.exe with the -command argument like follows:

powershell.exe -command "remove-item c:\utils\test\* -recurse -force"

 

Running this in PS doesn't seem to do anything,

remove-item C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\* -recurse -force 

On 08/02/2024 at 13:02, jamester64 said:

Running this in PS doesn't seem to do anything,

remove-item C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\* -recurse -force 

don't forget your quotes around the directory path due to the spaces

remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

and this would be run from powershell.exe instead of cmd.exe | or as a .ps1 file instead of .cmd

On 08/02/2024 at 11:08, Brandon H said:

don't forget your quotes around the directory path due to the spaces

remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

and this would be run from powershell.exe instead of cmd.exe | or as a .ps1 file instead of .cmd

Got it :-)

remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

Thank you

  • Like 3
On 08/02/2024 at 11:08, Brandon H said:

don't forget your quotes around the directory path due to the spaces

remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

and this would be run from powershell.exe instead of cmd.exe | or as a .ps1 file instead of .cmd

I'm having trouble running this in task schedule 

this is what I have in scheduler and I see PS quickly open then close but files remain, not sure what I am missing

-command remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

Annotation 2024-02-08 132328.png

On 08/02/2024 at 15:25, jamester64 said:

I'm having trouble running this in task schedule 

this is what I have in scheduler and I see PS quickly open then close but files remain, not sure what I am missing

-command remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

Annotation 2024-02-08 132328.png

if you're setting the 'program' to powershell.exe then you don't need '-command' at the beginning of your argument

On 08/02/2024 at 13:30, Brandon H said:

if you're setting the 'program' to powershell.exe then you don't need '-command' at the beginning of your argument

Program is set to Powershell.exe and added just this to argument and still not working in scheduler,        remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

not sure what I'm doing wrong

Edit- I just found a way to make it work by adding this  -ExecutionPolicy Bypass C:\Users\James\PlexClean.ps1

Edited by jamester64
On 08/02/2024 at 18:30, jamester64 said:

Program is set to Powershell.exe and added just this to argument and still not working in scheduler,        remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force

not sure what I'm doing wrong

Edit- I just found a way to make it work by adding this  -ExecutionPolicy Bypass C:\Users\James\PlexClean.ps1

I apologize for the late reply. If you wanted to avoid including -executionpolicy bypass and/or using a .ps1, the argument field should look like the following:

-command 'remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force'
# or alternatively this:
-command "remove-item 'C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*' -recurse -force"

The issue with what you had in there before was the missing single quote. By placing the entire command within a set of quotes (either single or double, but not the same ones you use for your folder path), you pass the entire quoted string into powershell.

If you want to continue using your powershell script file (.ps1), the argument field could look like this:

-executionpolicy bypass -file "c:\path\to\script.ps1"

It looks like you figured it out on your own, but I wanted to add this information for clarity.

--

On 08/02/2024 at 16:30, Brandon H said:

if you're setting the 'program' to powershell.exe then you don't need '-command' at the beginning of your argument

In regards to this, I think you only need the -command argument if you are not going to reference a script. I have not tested this however to see if -command is an implied argument for powershell. Another thing to note (according to the following link) is that the -command argument must be the final argument, otherwise the rest of the arguments are run as part of the -command arg. More information can be found here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1

On 09/02/2024 at 08:24, satukoro said:

I apologize for the late reply. If you wanted to avoid including -executionpolicy bypass and/or using a .ps1, the argument field should look like the following:

-command 'remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force'
# or alternatively this:
-command "remove-item 'C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*' -recurse -force"

The issue with what you had in there before was the missing single quote. By placing the entire command within a set of quotes (either single or double, but not the same ones you use for your folder path), you pass the entire quoted string into powershell.

If you want to continue using your powershell script file (.ps1), the argument field could look like this:

-executionpolicy bypass -file "c:\path\to\script.ps1"

It looks like you figured it out on your own, but I wanted to add this information for clarity.

--

In regards to this, I think you only need the -command argument if you are not going to reference a script. I have not tested this however to see if -command is an implied argument for powershell. Another thing to note (according to the following link) is that the -command argument must be the final argument, otherwise the rest of the arguments are run as part of the -command arg. More information can be found here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1

Thank you for the explanation of what i was doing wrong and the fix ;-) 

Did some testing and this line worked 

-command "remove-item 'C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*' -recurse -force"

This line did not 

-command 'remove-item "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder\*" -recurse -force'

 

# Specify directory to clear
$Path = "C:\Users\James\AppData\Local\Plex Media Server\Cache\PhotoTranscoder"

# Remove items
Remove-Item "$Path\*" -Recurse -Force

Save as Clear-PlexCache.ps1

Task scheduler:

Run: powershell.exe
Command arguments: -ExecutionPolicy Bypass -File "Clear-PlexCache.ps1"
Folder to start in: <path to script folder>

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Leave Secure Boot off, the Optiplex 7010 isn't getting a firmware update to support the changes...
    • Microsoft confirms Windows 11 26H2 to finally get one of the most requested features by Sayan Sen This past week Microsoft officially confirmed Windows 11 version 26H2 with the latest build, 26300.8697, for testing in the experimental Insider channel. The company also published more details about it mainly directed towards IT admins and system admins. Essentially version 26H2 will be delivered via an enablement package (eKB) over Windows 11 25H2. If you are wondering about some of the upcoming features in the next Windows version, one of them is certainly very interesting as Microsoft has confirmed it is finally bringing one of the most overwhelmingly requested features ever. March Rogers, the Partner Director of Design at Microsoft, recently highlighted some of the Search improvements that the company is testing, and during the interaction with users on X where he posted it, Rogers also confirmed that the company is working on disabling web search results inside Search. This is something which many users find quite annoying as Windows would often serve them links to Bing which it feels could be more helpful rather than bringing up the actual object or app the user may be searching for on their PC. Finally though the company is prioritizing local file search over the web. However the feature could not be disabled for many users as not all new features are immediately rolled out to everyone. Image via phantomofearth (X) Windows enthusiast phantomofearth who likes to dig deep into new builds uncovered the IDs you will need to enable these features. Using the following feature IDs the new Search-related features landing in Windows 11 26H2 can be used. Follow the steps below to enable the new Search experience on Windows 11 build 26300.8697: Download ViveTool from GitHub and unpack the files in a convenient and easy-to-find folder. Press Win + X and select Terminal (Admin). Switch Windows Terminal to the Command Prompt profile with the Ctrl + Shift + 2 shortcut or by clicking the arrow-down button at the top of the window. Navigate to the folder containing the ViveTool files with the CD command. For example, if you have placed ViveTool in C:\Vive, type CD C:\Vive. Type vivetool /enable /id: and press Enter. Restart your computer. If you change your mind and want to restore, repeat the steps above and replace /enable with /disable in the commands on steps 5 and 6. Delightedly and perhaps also expectedly, once you disable web search and other such bloat, the Windows 11 Search is said to get snappier as remarked by another Windows enthusiast Xeno.
    • Makes me think of Family Guy - "Carl Sagan's Cosmos... edited for Rednecks" 🤣 https://www.youtube.com/watch?v=Ljt5iESYA7k&t=2s
    • Microsoft PC Manager 3.21.7.0 (Offline Installer) by Razvan Serea With Microsoft PC Manager, users can easily perform basic computer maintenance and enhance the speed of their devices with just one click. This app offers a range of features, including disk cleanup, startup app management, virus scanning, Windows Update checks, process monitoring, and storage management. Microsoft PC Manager key features: Storage Manager- easily uninstall infrequently used apps, manage large files, perform a cleanup, and set up Storage Sense to automatically clear temporary files. Health Checkup feature -scans for potential problems, viruses, and startup programs to turn off. It helps you identify unnecessary items to remove, optimizing your system's performance. Pop-up Management - block pop-up windows from appearing in apps. Windows Update - scans your system for any pending updates. Startup Apps - enable or disable startup apps on your PC, allowing you to optimize your system's startup performance. Browser Protection - rest assured that harmful programs cannot alter your default browser. Also enables you to change your default browser. Process Management - allows you to conveniently terminate any active process, ensuring optimal system performance and resource utilization. Anti-virus protection - Fully integrated with Windows Security. Safeguard your PC anytime. Quick Steps: Download Microsoft PC Manager Offline Installer (APPX/MSIX) with Adguard Adguard serves as a third-party online service, offering a user-friendly method for directly downloading appx, appxbundle, and msixbundle files from the Microsoft Store. Official download links will be generated for both the app's various versions and its dependency packages. How to download Microsoft PC Manager Offline Installer (APPX/MSIX) 1. Initially, you must find the app URL within the Microsoft Store. Access the Microsoft Store via your browser and search for "Microsoft PC Manager". Once located, copy the app URL, which includes the product ID, either from the address bar or from the provided link below. https://apps.microsoft.com/detail/9PM860492SZD 2. Now paste the app URL into the designated area, then click the check mark button to produce a direct download link. 3. To download, right-click the relevant link and select “Save link as…” from your browser's menu. Occasionally, Microsoft Edge may flag the download as insecure. In such cases, consider utilizing alternative browsers such as Google Chrome or Firefox to successfully complete the download. Microsoft PC Manager is a completely free tool optimized exclusively for use on Windows 10 (19042.0 and above) and Windows 11. Download: Microsoft PC Manager 3.21.7.0 | from Microsoft Store View: Microsoft PC Manager Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • jspaint is a lot better, if you like the classic mspaint experience and hate the new bloated Paint.
  • Recent Achievements

    • Dedicated
      Almohandis earned a badge
      Dedicated
    • Dedicated
      JuvenileDelinquent earned a badge
      Dedicated
    • First Post
      DrWankel earned a badge
      First Post
    • Reacting Well
      DrWankel earned a badge
      Reacting Well
    • Week One Done
      Supreme Spray LV earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      505
    2. 2
      +Edouard
      177
    3. 3
      PsYcHoKiLLa
      84
    4. 4
      Steven P.
      76
    5. 5
      Michael Scrip
      76
  • Tell a friend

    Love Neowin? Tell a friend!