Jump to content

Making a script / batch for deleting specific file

Kanna

So I'm running a task which creates big files in the temp folder and I'm wondering if it is possible to auto delete it after like 5 minutes since my drive has been on 0 bytes left multiple times 

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

The easiest way would be to write a batch of PowerShell script to perform that action and use task scheduler to execute it every X minutes.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, schwellmo92 said:

The easiest way would be to write a batch of PowerShell script to perform that action and use task scheduler to execute it every X minutes.

What would I make the batch include? And would it work even if some files can't be deleted in the temp folder?

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, AnonimFan said:

"@echo off

del <file.txt>"

 

 

its that easy

I'm a noob at stuff like this but I'm pretty sure that won't loop the command as mentioned I want it to remove the file after X minutes also don't I need to specify directory?

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Kanna said:

I'm a noob at stuff like this but I'm pretty sure that won't loop the command as mentioned I want it to remove the file after X minutes also don't I need to specify directory?

You need to specify, unless if you changed the directory with the command cd

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, AnonimFan said:

You need to specify, unless if changed the directory with the command cd

so what would I type if the folder location was the %temp%?

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, AnonimFan said:

%temp%\"directory"\"file"

 

I would map it out like this

Where do I specify the time ammount?

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Kanna said:

Where do I specify the time ammount?

In task shecluder you can do that

 

Link to comment
Share on other sites

Link to post
Share on other sites

Put it on scheduled tasks .. run batch file every # minutes , or whatever.

 

It's Task Scheduler on Windows 7, no idea how it's named on Windows 10.

Make sure you launch the bat file with the working folder set to your TEMP folder or specify the whole path ... for ex. DEL %TEMP%\*.txt   to delete all .TXT files from the default TEMP folder.

 

It won't delete the files still opened or currently being written to

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, AnonimFan said:

In task shecluder you can do that

 

so I would make the bat 

"@echo off

del <C:\Users\XX\AppData\Local\Temp\X>"

and then add it to run in the task scheduler?

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

if you want i can do it in python for you

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, mahyar said:

if you want i can do it in python for you

Nah I just want it simple like now today only, but how fast would you get it done?

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Kanna said:

Nah I just want it simple like now today only, but how fast would you get it done?

maybe 10 to 20 mins

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, mahyar said:

maybe 10 to 20 mins

Then I will pass sorry

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Kanna said:

Then I will pass sorry

btw how much time between each delete and file type

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, mahyar said:

btw how much time between each delete and file type

10 minutes and it's a folder

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

19 minutes ago, mariushm said:

Put it on scheduled tasks .. run batch file every # minutes , or whatever.

 

It's Task Scheduler on Windows 7, no idea how it's named on Windows 10.

Make sure you launch the bat file with the working folder set to your TEMP folder or specify the whole path ... for ex. DEL %TEMP%\*.txt   to delete all .TXT files from the default TEMP folder.

 

It won't delete the files still opened or currently being written to

I don't know if I did it right I set it to run at 16:34 and repeat every 10 minutes

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

before using it open it up and replace folder with path of your folder

autodelete.py

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
Share on other sites

Link to post
Share on other sites

You can't delete a folder with DEL command, you can delete certain files from inside that folder with the DEL command

 

So you have to add either the file name, or a pattern .. *.* for example for ALL files (any name, any extension) , or *.TXT for all text files (any name, TXT extension) 

 

So your batch file should have DEL "C:\Users\YOUR USERNAME\AppData\Local\Temp\X\*.*"  - " " are required if there's a space or several spaces in the whole path.

Alternatively, you could use DEL %TEMP%\X\*.* 

 

You can set it to run every minute just to see that it works and does the job, then change to 10 minutes once you see it runs properly.

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, mahyar said:

before using it open it up and replace folder with path of your folder

autodelete.py 81 B · 1 download

should the quotes remain ("")?

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Kanna said:

should the quotes remain ("")?

yes

if it was useful give it a like :) btw if your into linux pay a visit here

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, mariushm said:

Yeah, and you'll need to install Python to get that to run, obviously.

nvm then 

Reminder⚠️

I'm just speaking from experience so what I say may not work 100%

Please try searching up the answer before you post here but I am always glad to help

Link to comment
Share on other sites

Link to post
Share on other sites

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

×