Deleting and recreating the Temp folder automatically

Started by gldisk

Deleting and recreating the Temp folder automatically   08 February 2021, 04:38

Hello to all the SoftPerfect's community.

I am using SoftPerfect RAM Disk so that it saves the contents to an .img file that contains the Firefox browser profile and the user's Temp folder.

Is there a way to delete and recreate the Temp folder on each reboot without having to place it in a volatile RAM disk?

Thank you.
SoftPerfect Support forum - Ann avatar image
Ann

Re: Deleting and recreating the Temp folder automatically   08 February 2021, 08:34

Is there a particular reason why you want to create a temporary folder in a non-volatile image file and then automatically delete it each time?

RAM disk .img files are used for non-volatile (persistent) data, but in this case the data is purposefully kept instead of being automatically deleted. So the scenario you are asking about, where a folder is created for permanent data storage and yet gets automatically deleted, seems quite unusual. That's why I'd like to clarify what you require this for.

Normally, if someone is using their RAM disk only for temporary data that they don't need to keep for future work, they want it to be volatile, and therefore they don't need an image file at all. Without an image file, the RAM Disk application works faster, and decreases reads and writes from the physical disk even further.

To get a Temp directory automatically created on a RAM disk, open the disk settings, and specify the Temp folder name in the File System Options - Create Folders section. You can add more than one folder to that list (type each name on a separate line), and use those folders for different purposes. They will all be automatically created each time together with the RAM disk, will be available to the system and other software during the working session, and then will be deleted together with all their contents every time you reboot or switch your computer off. That is, they will be volatile.

There may be a solution for your scenario if you use two different RAM disks: a volatile disk for Temp, and a persistent disk for Firefox profile.

Another way is to use a batch file for clearing out the Temp folder:
@echo off
cd /D %temp%
for /d %%D in (*) do rd /s /q "%%D"
del /f /q *
What this does:
  1. turns the command display off for the whole running script;
  2. changes the working directory of the batch file to the path from the %temp% system variable;
  3. deletes directories recursively, with all files and subdirectories, and without asking for confirmation;
  4. removes read-only files while skipping the prompts.

Re: Deleting and recreating the Temp folder automatically   10 February 2021, 04:22

Quote

Ann

Is there a particular reason why you want to create a temporary folder in a non-volatile image file and then automatically delete it each time?

The Firefox profile takes up about 150 MB, but the RAMdisk size should be at least twice that amount of space for future needs.
The user's Temp folder have varying space requirements depending on what data is put inside it.
Instead of creating a 300MB RAMdisk for Firefox and a 1GB RAMdisk for the Temp folder, I prefer to create only 1GB one, and pay attention on how the Temp folder grow in size, because not all programs delete the files created inside it, hence the need to delete and recreate it.

Quote

Ann

Another way is to use a batch file for clearing out the Temp folder ...

Can I use the SoftPerfect RAM Disk built-in AutoRun function to run .bat scripts like this ?
SoftPerfect Support forum - Andrew avatar image

Re: Deleting and recreating the Temp folder automatically   10 February 2021, 08:29

Yes, you can. Simply add the path to your batch file under Automatically Starting Applications and it should clear %TEMP% for you on every boot.

Re: Deleting and recreating the Temp folder automatically   18 February 2021, 20:52

In an attempt to hide the .bat file Dos window, I want to launch the execution with a .vbs script, but SoftPerfect RAM Disk built-in AutoRun function only supports running .exe, .cmd and .bat files.

Is there any way to add .vbs files as well ?
SoftPerfect Support forum - Andrew avatar image

Re: Deleting and recreating the Temp folder automatically   19 February 2021, 10:42

Yes, just type the script name directly in the file selection dialog. This will bypass the filter and you will be able add a VBS script.

Here is how it works:

SoftPerfect support forum

In the next RAM Disk release we will allow selecting VBS files as well.

Re: Deleting and recreating the Temp folder automatically   19 February 2021, 21:28

Perfect, thank You !

Sometimes you can find a solution faster if you try the forum search, have a look at the knowledge base, or check the software user manual to see if your question has already been answered.

Our forum rules are simple:

  • Be polite.
  • Do not spam.
  • Write in English. If possible, check your spelling and grammar.

Author:

Subject

A brief and informative title for your message, approximately 4–8 words:

     

Spam prevention: please enter the following code in the input field below.

 ********  ********  ********  ********   *******  
 **           **     **    **  **        **     ** 
 **           **         **    **               ** 
 ******       **        **     ******     *******  
 **           **       **      **               ** 
 **           **       **      **        **     ** 
 ********     **       **      ********   *******  

Message: