• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Any batch script gurus???

mcvickj

Diamond Member
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.
 
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
 
@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)
 
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.
 
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.
 
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 🙂






 
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.
 
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.
 
use the new edited code, I just compiled, tested it and ran it no prob. Also, there is a software forum for this stuff....
 
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.
 
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.

 
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?
 
Back
Top