Any batch script gurus???

mcvickj

Diamond Member
Dec 13, 2001
4,602
0
76
I have a folder named TEMP. What I want to do is delete everything inside this folder (files and folders) using a batch script.

Because of a security program named Fortres deleting the entire folder and recreating it is not an option.

Thoughts?

I tried del c:\temp\. /s /q This almost works. It will delete all of the files under TEMP but it won't delete sub directories.
 

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
I was at one point :beer:

If I wasn't in class, I'd get the answer for you. Mabye later if you still don't have an answer
 

hevnsnt

Lifer
Mar 18, 2000
10,868
1
0
@echo off
rd c:\%1 /s /q
md %1

usage

save as remdir.bat (or whatever)

'remdir temp'

This will delete the c:\temp directory and then recreate it. Or you could hard code it in there if you know exactly what you want to remove (change %1 to c:\temp for example)
 

Billzie7718

Senior member
Sep 2, 2005
649
0
0
Originally posted by: hevnsnt
@echo off
rd c:\%1 /s /q
md %1

usage

save as remdir.bat (or whatever)

'remdir temp'

This will delete the c:\temp directory and then recreate it. Or you could hard code it in there if you know exactly what you want to remove (change %1 to c:\temp for example)
In the words of the OP:

Because of a security program named Fortres deleting the entire folder and recreating it is not an option.
 

mcvickj

Diamond Member
Dec 13, 2001
4,602
0
76
Originally posted by: Billzie7718
Originally posted by: hevnsnt
@echo off
rd c:\%1 /s /q
md %1

usage

save as remdir.bat (or whatever)

'remdir temp'

This will delete the c:\temp directory and then recreate it. Or you could hard code it in there if you know exactly what you want to remove (change %1 to c:\temp for example)
In the words of the OP:

Because of a security program named Fortres deleting the entire folder and recreating it is not an option.

Hehe. Thanks Billzie. I could allow for this action but then it opens up one more thing a patron could do on the computer. If it is possible I would like to avoid it.
 

HumblePie

Lifer
Oct 30, 2000
14,665
440
126
Why a batch? why not write some actual code?

Here's some simple java. Just go to http://java.sun.com and download the SDK (software developer kit) from there. Install it. Then open a text pad. Use this code. Save the file as DelTree.java.
import java.lang.reflect.*;
import java.io.*;
import java.text.*;
import java.util.*;

public class DelTree
{

public static void DelTree(File source) throws Exception
{
if (source.isDirectory())
{
File[] list=source.listFiles();
for (int n=0; n<list.length; n++)
{
if (list[n].isDirectory())
{
DelTree(list[n]);
list[n].delete();
}
else
{
list[n].delete();
}
}
}
}

public static void main(String[] args)
{
String tmp = args[0];
File source = new File(tmp);
try
{
DelTree(source);
source.delete();
}
catch (Exception e){}
System.exit(0);
}
}



Wow, not really hard. just compile that with a command line:

javac DelTree.java

then run it with...

java DelTree <insert directory name you want to remove completely>



Fairly simple and took me all of 3 minutes to do.

Edit fixed it, was using some copy and paste code I had done before :)






 

Ipno

Golden Member
Apr 30, 2001
1,047
0
0
hahaha, leave it to windows to make "rm -rf /tmp/*" a 3 minute script.
 

Billzie7718

Senior member
Sep 2, 2005
649
0
0
If it needs to be a batch file then you will probably need to get a little more complex. Like, pull a list of the contents of that directory and then point the batch to delete those specific files.
 

mcvickj

Diamond Member
Dec 13, 2001
4,602
0
76
Nope. No real reason why it has to be a batch script. Was just trying to something quick and easy. I'm looking into that code HumblePie posted.
 

HumblePie

Lifer
Oct 30, 2000
14,665
440
126
use the new edited code, I just compiled, tested it and ran it no prob. Also, there is a software forum for this stuff....
 

Billzie7718

Senior member
Sep 2, 2005
649
0
0
Originally posted by: mcvickj
Nope. No real reason why it has to be a batch script. Was just trying to something quick and easy. I'm looking into that code HumblePie posted.

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("C:\temp\*.*")
objFSO.DeleteFile("C:\temp\*.*")


^^^^^^^^^^^^^^^^^^^^^^^^^^
Rename it test.vbs and double click it.

Done and Done.
 

Billzie7718

Senior member
Sep 2, 2005
649
0
0
Originally posted by: Billzie7718
Originally posted by: mcvickj
Nope. No real reason why it has to be a batch script. Was just trying to something quick and easy. I'm looking into that code HumblePie posted.

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("C:\temp\*.*")
objFSO.DeleteFile("C:\temp\*.*"), DeleteReadOnly

^^^^^^^^^^^^^^^^^^^^^^^^^^
Rename it test.vbs and double click it.

Done and Done.

Fixed ... in case there actually is a read only file, it will delete it also.

 

TechnoPro

Golden Member
Jul 10, 2003
1,727
0
76
Originally posted by: mcvickj
I have a folder named TEMP. What I want to do is delete everything inside this folder (files and folders) using a batch script.

Because of a security program named Fortres deleting the entire folder and recreating it is not an option.

Thoughts?

I tried del c:\temp\. /s /q This almost works. It will delete all of the files under TEMP but it won't delete sub directories.

Can you delete any folder on the system? Or does Fortres only restrict certain ones from deletion?