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

    • This is why science is the only path to truth. It isn't rigid in its beliefs, rather it changes its views based on scientific discoveries.
    • A 13 billion year old secret about our Universe's origin was revealed by Sayan Sen Image by Pascal Küffer via Pexels Researchers at the Max-Planck-Institut für Kernphysik (MPIK) in Heidelberg had recreated a key chemical reaction from the early universe, producing results that could change scientists' understanding of how the first stars formed. The study focused on the helium hydride ion (HeH⁺), which is widely regarded as the first molecule to form in the universe. Scientists believe HeH⁺ appeared around 380,000 years after the Big Bang, when the universe had cooled enough for electrons and atomic nuclei to combine into neutral atoms in a period known as recombination. This marked the beginning of chemistry in the cosmos. Immediately after the Big Bang about 13.8 billion years ago, the universe was extremely hot and dense. As it expanded and cooled, hydrogen and helium became the dominant elements. Once neutral helium atoms formed, they could react with ionised hydrogen nuclei, or protons, to create helium hydride ions. Although simple in structure, HeH⁺ played an important role in the young universe. It was the first step in a chain of reactions that eventually produced molecular hydrogen (H₂), a molecule made up of two hydrogen atoms and now the most abundant molecule in the universe. Molecular hydrogen later became a key ingredient in the formation of the first stars. At the time, the universe had entered a phase often called the cosmological "dark age." Matter had become transparent to light following recombination, but there were still no stars or galaxies producing visible light. Several hundred million years would pass before the first stars appeared. For those first stars to form, large clouds of gas had to collapse under their own gravity. To do that, the gas needed to cool by releasing energy. While hydrogen atoms can help with this process at high temperatures, they become less effective below about 10,000 degrees Celsius. Molecules can continue the cooling process by releasing energy through rotational and vibrational motions. Scientists have long considered HeH⁺ a potentially important coolant because of its comparatively large dipole moment, a property that describes how electric charge is distributed within a molecule and allows it to release energy efficiently. The amount of helium hydride present in the early universe may therefore have influenced how easily the first stars could form. At the same time, HeH⁺ was constantly being destroyed. Under primordial conditions, its main destruction mechanisms were recombination with free electrons and chemical reactions with hydrogen atoms. These reactions ultimately helped produce molecular hydrogen, linking the formation and destruction of HeH⁺ to the chemistry that shaped the early universe. For many years, theoretical studies suggested that reactions between HeH⁺ and hydrogen atoms would become much slower at low temperatures. Scientists believed there was an energy barrier along the reaction pathway that reduced the chances of the reaction taking place in the cold conditions of the early universe. The new study suggests otherwise. To investigate the process, researchers recreated a closely related reaction using deuterium, a naturally occurring isotope of hydrogen that contains one proton and one neutron in its nucleus. When HeH⁺ collides with deuterium, it forms an HD⁺ ion and a neutral helium atom. This allows scientists to study the reaction in a controlled way while closely mimicking the behaviour of the original reaction involving hydrogen. The experiments were carried out at the Cryogenic Storage Ring (CSR) at MPIK, a specialised facility designed to recreate conditions similar to those found in space. Researchers stored HeH⁺ ions in the 35-metre storage ring for up to 60 seconds at temperatures just a few kelvins above absolute zero and merged them with a beam of neutral deuterium atoms. By adjusting the speeds of the two particle beams, the team measured how the reaction rate changed with collision energy, which is directly related to temperature. The researchers found that the reaction rate remains almost constant as temperatures decrease. In other words, the reaction does not slow down at low temperatures as earlier models predicted. “Previous theories predicted a significant decrease in the reaction probability at low temperatures, but we were unable to verify this in either the experiment or new theoretical calculations by our colleagues,” explained Dr Holger Kreckel of MPIK. “The reactions of HeH⁺ with neutral hydrogen and deuterium therefore appear to have been far more important for chemistry in the early universe than previously assumed,” he continued. According to the researchers, the reaction appears to be barrierless, meaning there is no energy obstacle preventing it from taking place efficiently even at very low temperatures. The findings support recent theoretical work led by physicist Yohann Scribano, whose group identified an error in a widely used potential energy surface, a mathematical model used to describe how the energy of a system changes during a chemical reaction. The error appears to have caused previous studies to significantly underestimate reaction rates under primordial conditions. The new calculations closely match the experimental results. Together, they suggest that helium chemistry in the early universe may need to be re-evaluated. Because molecules such as HeH⁺ and molecular hydrogen played an important role in cooling primordial gas clouds, the findings could help scientists build more accurate models of how the first stars formed. By showing that helium hydride was likely destroyed more efficiently than previously thought, the study offers new insight into the chemical processes that shaped the universe during its earliest stages and helped set the conditions for the emergence of the first stars. Source: Max-Planck Institute, EDP Sciences This article was generated with some help from AI and reviewed by an editor. Under Section 107 of the Copyright Act 1976, this material is used for the purpose of news reporting. Fair use is a use permitted by copyright statute that might otherwise be infringing.
    • "What an interesting smell you've discovered"
    • It could EASILY be 70 for the base game BUT + lots of FOMO to make it up to 100-120, like a few days Early Access, online money, pre-order bonus cars, weapons, missions, clothing, avatars or profile stuff, etc... And still WAY TOO MANY people would buy those and make Rockstar insane money.
    • Just to understand: your solution to getting rid of an online password manager is...another online password manager?
  • Recent Achievements

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

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

    Love Neowin? Tell a friend!