Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

batch file that will delete folders

Original Message
Name: jds123
Date: January 27, 2004 at 11:49:49 Pacific
Subject: batch file that will delete folders
OS: w 2000
CPU/Ram: p4 256
Comment:
Hi there

I'm having trouble accomplishing the below.

I would like a batch file that will delete sub directories and the files contained in them, but it should keep the latest 10 sub directories.
example- c:\test\ contained in this directory are sub directories named jan012004,
jan022004...jan102004.

In the event of a new dir being added to c:test\ ie - jan112004, jan012004 should be deleted by the batch program. However if no new sub directory is added ie jan112004 the oldest sub directory should not be deleted by the batch program ie jan012004.

Thanks very much....


Report Offensive Message For Removal


Response Number 1
Name: Wengier
Date: January 27, 2004 at 12:09:28 Pacific
Subject: batch file that will delete folders
Reply: (edit)
Hi friend, this is DOS forum. You have asked your question in a *wrong* forum. Please note that Windows 2000 does not include "DOS". The "Command Prompt" in Win2K is just the WinNT/2K/XP system console, which is NOT DOS. Below is the *quotation* from the warning messages of this forum:

"DO NOT post questions related to NT Batch scripting on this forum. Use the Programming forum.

Use the Windows NT, 2000 or XP forum for questions regarding the Windows NT, 2000 or XP "DOS" command prompt."

For more information about the "Command Prompt" (Win32 Console) in WinNT/2K/XP, you may read this page:

http://mywebpages.comcast.net/stewartb/cmdprompt.html


Report Offensive Follow Up For Removal

Response Number 2
Name: Homegrown
Date: January 27, 2004 at 22:09:49 Pacific
Subject: batch file that will delete folders
Reply: (edit)
Excuse me but what makes you so sure he is in the *wrong* forum. I don't see any mention of what operating sytem he he using. For all you can tell from his post he could be running msdos2.0 on a 64k comodore. I think you are out of line here Wengier. And by the way I have batch files that I run by clicking on the file in windows explorer (Win 95c) and I amm fairly sure that I can get my xp pro computer to run them too.

Hi JDS.... Try seting up your batch file using the attrib command to set the archive attribute on all files after a certain date, remove the "A" attribute on all files before that date and then xcopy all files in the root folder that have the "A" attribute turned on to a temporary folder, delete all the subdirectoies/files in"c:\test using the delete or the deltree (use with extreeme caution) commands. If you get error messages that say bad command and you know that you spelled everything right you may have to boot from a floppy disk with an OS that suppors the commands you want. I personally recomend dos 6.2 partly because it has the most comprehensive help file of all microsofts efforts. good luck I may be back aftyer I do some research on this.


Report Offensive Follow Up For Removal

Response Number 3
Name: Dan Penny
Date: January 28, 2004 at 03:12:21 Pacific
Subject: batch file that will delete folders
Reply: (edit)
" I don't see any mention of what operating sytem he he using."

In the header of his message it states w2000.


Report Offensive Follow Up For Removal

Response Number 4
Name: Wengier
Date: January 28, 2004 at 06:15:13 Pacific
Subject: batch file that will delete folders
Reply: (edit)
Homegrown,

So, please read the poster's "OS" column carefully before trying to make a reply, thanks.


Report Offensive Follow Up For Removal

Response Number 5
Name: Homegrown
Date: January 28, 2004 at 15:45:02 Pacific
Subject: batch file that will delete folders
Reply: (edit)
OK so he is running win 2000. If win2k,xp etc. are not in fact DISK OPERATING SYSTEMS (DOS), then how do they operate disks, for example floppys and hard drives? Should the forum be reffered to as "command prompt" rather than as "DOS"? I have old versions of MICROSOFT DISK OPERATING SYSTEMS, that do in fact incorperate graphical user interfaces, although they are very basic, and not designed for a mouse. Don't mean to be picky here but a D.O.S. is a disk operating system wether it is called MSDOS or UNIX or Windows.

Report Offensive Follow Up For Removal


Response Number 6
Name: Wengier
Date: January 28, 2004 at 16:38:00 Pacific
Subject: batch file that will delete folders
Reply: (edit)
Homegrown,

You mean all OSes are DOS (Disk Operating System)?! Quite funny, isn't it?


Report Offensive Follow Up For Removal

Response Number 7
Name: Jemuzu
Date: January 28, 2004 at 17:32:58 Pacific
Subject: batch file that will delete folders
Reply: (edit)
what abiut those old tape ones? they didn't use floppy discs... so... does that mean that... i'm using random knowledge at a random time?

Report Offensive Follow Up For Removal

Response Number 8
Name: mcocker
Date: January 30, 2004 at 07:10:40 Pacific
Subject: batch file that will delete folders
Reply: (edit)
You guys are strange. His question applies to batch files deleting directories. Personally I find nothing wrong with the post. Can you do this with DOS? YES. Will the same commands work under W2Ks command prompt? YES.

jds123, Homegrown is on the right track.


Report Offensive Follow Up For Removal

Response Number 9
Name: Maineh
Date: January 30, 2004 at 07:47:07 Pacific
Subject: batch file that will delete folders
Reply: (edit)
First, the OS column can be autofilled. So it might not be the OS that he's wanting to do this with.

Second. Run the MS-DOS editor, and type in the following.
ATTRIB %1\*.* -R -A -S -H
DELTREE %1

Now save it as whatever you want to name it, as long as it's followed by a .BAT extension, and is located in the PATH.
Say you name it DELDIR.BAT
and you want to delete the folder C:\DIR
you would type in DELDIR.BAT C:\DIR

It would then execute the commands in the DELDIR.BAT file as follows.
ATTRIB C:\DIR\*.* -R -A -S -H
DELTREE C:\DIR

The %1 is a variable, that will be replaced by why whatever you type in after the batch file command (in this case C:\DIR
Hoe that helped.


Report Offensive Follow Up For Removal

Response Number 10
Name: FishMonger
Date: January 31, 2004 at 11:45:46 Pacific
Subject: batch file that will delete folders
Reply: (edit)
Personally, I've never understood why so many people on this site get their feathers ruffled because someone posts a batch file question in the DOS section. While I do agree that there are better sections for it, I don't see or understand the problem in posting it here. Unfortunetly, Justin (the one and only moderator of this forum) has been convinced by these people that batch file questions MUST be posted in the Programming forum.

I think Maineh missed the fact that you want to automate the deletion of the directories while at the same time save the newest 10 directories (based on their names). Homegrown's method should work just fine, although he/she didn't provide any code to show you how to accomplish it.

If you want to “think outside of the box” and use a more powerful scripting language, Perl can easily accomplish this and would be more readable and very possibly fewer lines of code than the batch file. If you want to go with Perl, I'd be happy to write the script for you.


Report Offensive Follow Up For Removal

Response Number 11
Name: Dos Camel
Date: January 6, 2006 at 13:27:08 Pacific
Subject: batch file that will delete folders
Reply: (edit)
I have an assembly language program I am using with both win me and win2k pro in the dos prompt. deldir.exe. It works well with 8 character file names but will not delete files such as "my file" but will work with files names such as "my_file_name" which is longer than eight characters. This program will delete all the files in all subdirectories in the directory you are in unconditional wheather a r s h attributes are set. I will send this program to you in an attachment via e-mail if you request it.
jtaft@alltel.net

I no longer have the source code of this program. Sadley, I lost it.

Jessie Taft


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: batch file that will delete folders

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12

help mandriva install last straw!

Icon Scaling in Explorer Bar


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC