0

I have this commen issue with photoshop. Where it doesn't delete the temp files it creates after a shutdown of program.

I have used alot of time to find a script that would delete all files with starting name of Photoshop* in the temp, which is older than 2 days. So i dont delete files, if i get a unexpected shutdown or crash.

I tried this, after a few hours of search - but it doenst work

ForFiles /p "C:\Users\user\AppData\Local\Temp\Photo*" /s /d -2 /c "cmd /c del @file"

This works, perfectly but it deletes all files without taking into consideration how old the files are.

C:\
del "C:\Users\user\AppData\Local\Temp\Photoshop*."

How can i get the above script, which runs on every startup with system rights. To only delete all files starting with photoshop* and are older than 2 days :)

I need this script to work on Windows10 and Windows7

Every input is appreciated.

Neo1234
  • 45
  • 7
  • Take a look [at this question](https://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days), the syntax is different – Dwhitz Feb 21 '18 at 13:24
  • Hey Dwhitz - Did notice that post in my search on google, but didnt actually understand all the answers inside, i have tried a few and testet it. But it doenst work on my machine after editing and trying for a few hours. – Neo1234 Feb 21 '18 at 13:41
  • In **best answer** there is an update of syntax : `forfiles /p "C:\what\ever" /s /m *.* /D - /C "cmd /c del @path"` have you tried that? – Dwhitz Feb 21 '18 at 13:47
  • Yes, at you can see in my post - thats the one i tried first, though i changed to file instead of path after but none of them worked – Neo1234 Feb 21 '18 at 14:20
  • But the answer say to use @path where path is the **full** path. See [this comment](https://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days#comment2461957_51069). Did u put the full path? Remember that this command can change for your os version, so please update your question with your os version. – Dwhitz Feb 21 '18 at 15:05
  • I tried both file file and path without any succuss :( – Neo1234 Feb 22 '18 at 12:15
  • Try to add a new line, and a pause after your command, so you can see eventual errors.. Like this: `forfiles /p "C:\folder\ " /s /m *.* /D -2 /C "cmd /c del @path" pause` – Dwhitz Feb 22 '18 at 14:26
  • Just a thought can this line be used if im running this in a notepad as a .bat job? or do i need to run in directly in the cmd :/ That might be the problem for why it doenst work – Neo1234 Feb 23 '18 at 10:30
  • Just tried again and it didnt work on my windows10 Client - and the pause function doenst do anything – Neo1234 Feb 23 '18 at 10:39
  • Try to **save** your file with `bat` extension. For example `deleteFiles.bat` and double click on it. The command `pause` allow you to see [error like this](https://i.snag.gy/oZrgQt.jpg) – Dwhitz Feb 23 '18 at 12:58
  • Its already called DeletePhotoTemp.bat but the pause funktion doenst give any result or indication. It opens cmd and runs the script and closes again without any error - but the files is still in the folder – Neo1234 Feb 23 '18 at 13:51
  • mmh.. it's weird. The `pause` should stop the bat waiting an input, so you can see any eventual errors just like my [previous screenshot.](https://i.snag.gy/oZrgQt.jpg) – Dwhitz Feb 23 '18 at 14:09
  • Try this `forFiles /p "C:\Users\neto\AppData\Local\Temp\Photo" /s /m *.* /D -2 /c "cmd /c echo @path"`, this will show the files that match your script. – Dwhitz Feb 23 '18 at 14:29
  • Didnt make a difference, but your suggestion indicates that their should be a folder called photo, which i dont have. Its the same with and without the pause – Neo1234 Feb 23 '18 at 14:46
  • First, checks that you have **file older than 2 days**, to make sure of that copy a file that has at least 3 days. Then try this `forfiles /p "C:\Users\neto\AppData\Local\Temp\" /s /m "*Photo*" /D -2 /C "cmd /c echo @file"` this will **output** all file that start with *Photo* ! Pay attention that show all the files in your dir and *subdirs*! – Dwhitz Feb 23 '18 at 15:35
  • Btw, is so strange that you don't see **any error**. Because i've just tried to use `/p "C:\anyPath\Photo*"` and it gives me one error, **dir not valid**. Because anything with `*` at the and is not a mask. Please check the output of your console. – Dwhitz Feb 25 '18 at 11:31
  • Neo1234 let me know if the script in previous comment show your files starting with `photo`. – Dwhitz Feb 27 '18 at 10:51
  • Hello Dwhitz, it doenst give me a output off the files. It keeps closing the prompt right away :( – Neo1234 Feb 28 '18 at 07:18
  • If i run the cmd directly in the command prompt it - i get "ERROR: Invalid argument/option - '@file'. I only tried the entries in the .bat file on windows 10 but i need it to work with both 7 and 10 – Neo1234 Feb 28 '18 at 07:20

0 Answers0