Automatic cache clearing .bat file for windows

  • Check out our Partnered Grand Theft Auto 5 Roleplaying Community New Day RP!

Drey Shadowfox

Gunslinger
Sheriff's Office
Whitelisted
Gold Supporter
Jul 29, 2020
124
200
93
So, want to clear that cache automatically every time you start RedM? I got you.

First things first. Let's get familiar with a couple of things:

  • a .bat file is a text file named with the extension .bat
  • a .bat file houses specific text commands native to windows for processing single commands in a batch
  • a .bat file once named to the extension .bat, will not be used like a text file anymore. It will try to run the lines of commands within it
  • Your RedM folder does not have to be in it's default installation folder. You can copy paste the entirety of the RedM installation where ever you want, and make a new shortcut to it
  • Why do this? Clearing your cache deletes the current loaded scripts for the server and forces them to be updated. By doing this, you can avoid a lot of trouble shooting issues and also ensure you have the latest updates for the server scripting.

So, lets make that bat file. I personally keep the bat file inside of the RedM folder, but you can keep it anywhere on your computer

  • The default install location for RedM is C:\Users\[YOUR USERNAME]\AppData\Local\RedM
  • So, if your username on your computer is todd it would be c:\Users\todd\AppData\Local\RedM

Make the file

  • Decide where you want to keep your bat file
  • In this example we will be making it inside the RedM folder
  • navigate to C:\Users\[YOUR USERNAME]\AppData\Local\RedM
  • inside create a text file with any name you choose

new text.png

  • for this example we will name it RedM Run

redmruntext.png

  • Now open this text file and insert the following commands one on each line.

del /s /q C:\Users\[YOUR USERNAME]\AppData\Local\RedM\data\server-cache\*
del /s /q C:\Users\[YOUR USERNAME]\AppData\Local\RedM\data\server-cache-priv\*
cmd /c start "" "C:\Users\[YOUR USERNAME]\AppData\Local\RedM\RedM.exe" -b1491
timeout /t 1
exit

Alright, cool, what do those lines do?
  • This command says to delete any file within the folder server-cache = del /s /q C:\Users\[YOUR USERNAME]\AppData\Local\RedM\data\server-cache\*
  • This command says to delete any file within the folder server-cache-priv =del /s /q C:\Users\[YOUR USERNAME]\AppData\Local\RedM\data\server-cache-priv\*
  • This command tells the computer to run the RedM executable inside the command window with the client version 1491 = cmd /c start "" "C:\Users\[YOUR USERNAME]\AppData\Local\RedM\RedM.exe" -b1491
  • This command asks for a 1 second time out. This is here in case an error pops. It gives you a stop point regardless in case of error to hit a key to exit. = timeout /t 1
  • This command, because we used cmd /c start, earlier, now allows us to use this one to close the command window = exit

Now save and on with the show.

  • Rename the text file extension from .txt to .bat. So RedM Run.txt should now be RedM Run.bat

RedMbat.PNG

  • As, you can see I created a shortcut to it. This is to test the bat file via a shortcut to make sure admin privileges work on it, in case I/You want it elevated easily (run as admin)
  • You can create a shortcut to it, in the same folder by right clicking RedM Run.bat and choosing create shortcut
  • There are good security reasons to run admin on a shortcut and not an actual .bat file. If you want to debate it with me do it elsewhere, not here, please.
Now for the real shortcut

  • On your desktop, right click and choose new shortcut

newshortcut.png

  • Now it will ask for a location
  • It really doesn't matter where, as we will be replacing everything, but for practice navigate to your RedM folder


location.png

  • Click next then name it whatever you want
  • Now right click the shortcut and choose properties, it will open a window
  • Don't let my picture below confuse you this is my installation but I had no way of editing it to show what we've used so far. Windows is a bitch sometimes.
  • As you can see I have the target section highlighted
  • You are going to edit that information

runbatshortcutedit.png

  • You want to change the target to:

C:\Windows\System32\cmd.exe /c "C:\Users\[YOUR USERNAME]\AppData\Local\RedM\RedM Run.bat"

  • You want to change the section "Start in:" to:

C:\Users\[YOUR USERNAME]\AppData\Local\RedM

  • Click ok
  • Now you have a specialized shortcut on your desktop, and clearing the cache every time
  • You can pin this in your start menu or add it to your quick launch
  • You can change the icon and set admin privilages or not
If you did it correctly it should look like this when it runs:

done.png

Hope this helps you in your WWRP endeavors. Have fun, be safe, be good, or be good at not getting caught.
 
Last edited by a moderator:

Drey Shadowfox

Gunslinger
Sheriff's Office
Whitelisted
Gold Supporter
Jul 29, 2020
124
200
93
Updated: 1/29/2022 for all builds including canary or backward compatible versions
 
Last edited:

Drey Shadowfox

Gunslinger
Sheriff's Office
Whitelisted
Gold Supporter
Jul 29, 2020
124
200
93
Updated: 2/20/2022 for all builds including canary or backward compatible versions. Removed 1 sec pause after deletion. Added secular command for both lines with no echo.
 

Petra Blackheart

"Don't be a Muppet!"
Staff
Media Engagement
Department of Prisons
Whitelisted
Gold Supporter
Oct 15, 2020
3,784
1,515
238
United States
twitch.tv
This has been moved and pinned in the "Rules, Guidelines, and Guides" section for easier finding and use by the community! Thanks for this amazing tutorial @Drey Shadowfox

I've been using this method for a long time now and its super convenient and makes life easier.

If for some reason you need to change your build that RedM launches with, make sure you follow this guide as well, and match it to the BAT file you run:
Setting your RedM Build Manually