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

    • Surprise! We still can't get it right. With the current state of AI, the crappy software, the huge mega-corporations that back all of these idiot things, I think we are a very long way away from SAE Level 5. I, for one, will never get in one.
    • Nice. September/October GA?! I'll keep following it, but won't install any preview or beta versions.
    • Wow, that could have been dangerous, certainly not ready for these things. They have to be 100% or pretty well close to it. Not that I will see one i doubt, never mind ride in one, they may have them in London, but I doubt they will come to where I live.
    • Nothing kills CMF Phone 2 Pro's successor due to rising memory prices by Hamid Ganji Storage and RAM prices have been rising over the past year, leading to a significant increase in the cost of electronics for customers around the world. Many companies are now revising their plans for upcoming devices due to higher component costs and overall production expenses. CMF is the latest company to cancel the successor to one of its best-selling phones due to rising memory prices. CMF is a sub-brand of Nothing and focuses on making budget smartphones for growing markets. The brand launched the CMF Phone 2 Pro last year with some eye-catching specifications and an affordable price. While many customers may have been waiting for a successor this year, one of the company’s executives has announced that CMF will not release a new smartphone this year. And AI is to blame. As Nothing co-founder Akis Evangelidis announced on X, the company has been working on a successor to the CMF Phone 2 Pro, but with current memory prices, it cannot “build a phone that feels like a genuine step forward at a price that makes sense for CMF.” So, no new CMF phone will be launched this year. Meanwhile, Evangelidis said the company still has several new products in the pipeline, including some in entirely new categories. He added that the Nothing brand will also continue launching new products through 2026. Budget smartphones are among the first victims of the surge in RAM and memory prices, as they have become more expensive to build. The sharp increase in memory costs could also reshape the traditional price ranges associated with budget phones. Apple CEO Tim Cook also recently said that price increases for some of the company’s products are unavoidable because RAM and memory have become significantly more expensive this year. Analysts estimate that the base price of the upcoming iPhone 18 Pro could rise to $1,399 due to current market shortages.
    • Nudge me when they bring back hardware audio acceleration so I can get my EAX 5 back. We've evolved graphics to real-time path tracing, but regressed audio some 15 years back in time with this stupid software audio stack.
  • Recent Achievements

    • Collaborator
      ryansurfer98 went up a rank
      Collaborator
    • Week One Done
      Eurosoft10 earned a badge
      Week One Done
    • One Month Later
      Eurosoft10 earned a badge
      One Month Later
    • One Year In
      Skeet Campbell earned a badge
      One Year In
    • One Month Later
      Sharbel earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      541
    2. 2
      +Edouard
      187
    3. 3
      Michael Scrip
      77
    4. 4
      PsYcHoKiLLa
      75
    5. 5
      Steven P.
      71
  • Tell a friend

    Love Neowin? Tell a friend!