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

    • FIFA cup is a worldwide event. Total global engagement — FIFA World Cup Qatar 2022 (official FIFA report) 5 billion people https://theworlddata.com/fifa-...-cup-viewership-statistics/ U.S., Canada, Japan drive vast World Series viewership for Games 1 and 2 In Japan despite a 9 a.m. local start time, Game One averaged 11.8 million viewers on NHK-G https://www.mlb.com/news/2025-...ching-large-global-audience There are also millions of annual viewers of the World Series in Latin America, especially Venezuela and the Domincan Republic due to the large number of players from those countries playing in the Major Leagues.
    • The original word arts were far more awesome! With their own preconfigured fill patterns, 3D layout, etc. I especially loved the ones circled below and still miss them from my primary school years: I frankly use them less these days 'cause the new one isn't as straightforward fine art as what we originally had. Same with the built-in picarts selection.
    • What didn't you understand about that was mainly referring to Google, Microsoft, etc. keeping your passwords. Password Management is a key service of Bitwarden and it's not going anywhere. In any case they do offer export to other Password management services, backup/download of passwords, and the already mentioned on-prem option. I don't agree with the OP to use the free option as it's better to be an actual customer IMO. They don't just don't delete accounts like the big tech companies with no recourse which was the main concern of this article. I was confused if the author was trying to sell this setup? It should be obvious to anyone reading this article this solution is overly complicated and overkill for most users.
    • I got this notification just now in Android: So I went in to disable the "Other" or "Marketing" notifications in Notifications management: But it came through the Now Playing? So if I disable that I no longer get what's Now Playing in Notifications? I'm a paying subscriber, not on the free plan... can they sink any lower?
    • Population especially in high density areas creates more heat and more humidity. This can be noticed in an indoor arena or concert room which heats up when the room or arena fills with people, without air conditoning to cool it down, Watering of lawns creates more humidity as the moisture from the watering rises into the atmosphere, creating a more humid condition. The again, depopulating an arena or room after an event will drop the temperature inside. Desert areas are less humid for a number of reasons, including a lower population density. Tel Aviv has horrible weather, unless you like it hot and humid. Summer days are regularly 90+ F with humidity well over 70%. It is probably not as bad as Mississippi but still it is bad enough.
  • Recent Achievements

    • 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
    • One Month Later
      Genuinetonerink- Dubai earned a badge
      One Month Later
    • Week One Done
      Genuinetonerink- Dubai earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      +Edouard
      163
    3. 3
      PsYcHoKiLLa
      91
    4. 4
      Steven P.
      75
    5. 5
      Michael Scrip
      72
  • Tell a friend

    Love Neowin? Tell a friend!