multiple sub-directory erasing

  • Thread starter Pierre Desrochers
  • Start date
P

Thread Starter

Pierre Desrochers

Hi all,

In a SCADA application we have, we create some sub-directories for archive
purposes. The problem we have is that some apps will create a .TMP or .BAK
files is them when used to check on those files.

Is there a command in DOS or other (we use Win NT) where we could say once a
day start this batch file which would erase all those .TMP and .BAK files in
a directori ... INCLUDING those in all it's sub-directory... we are running
out of space.

Thanck in advance

Pierre Desrochers
Integral Instrumentation Inc.
Montreal - Canada
 
H

Hullsiek, William

<pre>
This VB-script requires Windows Scripting Hosting which comes bundled
with MS-Explorer plus alot of other useful tools at no cost to consumer.



'
' File: Delete files
' Purpose: Delete older than N days
'
' Revision Control History
'
' Date Author Change
' ---------- --- -----------
' 01-Aug-2001 wfh sent to automation list
'
' Description
'
' Deletes files in NT folder
'
' Usage:
' This intended to run as a scheduled task, once a day.
'
'
' Global Variables
'
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

DIM mBln_Debug ' Debug Flag
DIM mBln_Cancel ' Cancel flag

DIM mObj_FSO ' File Sysem Object
DIM mStr_msgbox_Title ' Title used for msg box

mBln_Debug = False
mBln_Cancel = False
mStr_msgBox_Title = "Delete Welder Files"
Set mObj_FSO = CreateObject("Scripting.FileSystemObject")

result = Main()

Function Main()

dim objFolder
dim objDate

myDate = Date
strYYYY = cstr(DatePart("yyyy", myDate))
strMM = cstr(DatePart("m", myDate))
strDD = cstr(DatePart("d", myDate))

If mBln_Debug Then
log_event "Start Delete of Welder Files Archive"
End If

str_folder = "\\???? "
If mobj_FSO.FolderExists(str_folder) Then
set objFolder = mobj_FSO.GetFolder(str_folder)
ignore = Cleanup_Sub_Folder (objFolder)
End If

set mObj_FSO = Nothing
set objFolder = Nothing

If mBln_Debug Then
log_event "End of Session"
End If

End Function

sub log_event (strValue)

kbResponse = MsgBox (strValue, vbOKCancel + vbInformation,
mStr_msgbox_Title)
If kbResponse = VbOK Then
exit sub
Else
mBln_Cancel = True
exit sub
End If

end sub

Function Cleanup_Sub_Folder (byVal objFolder)
'
' Recursive routine to delete files in a folder.
'
dim oCollection
dim oFolder
dim oFile

For Each oFile in objFolder.Files
n = DateDiff ("d", oFile.DateLastModified, Now)
If n > 45 Then
If mBln_Debug = True Then
log_event "deleting " & oFile.Path & " after
" & n & " days"
If mBln_Cancel = True Then
Cleanup_Sub_Folders = False
Exit Function
End If
End If
oFile.Delete True
End If
Next

set oCollection = objFolder.SubFolders
For Each oFolder in oCollection
If NOT Cleanup_Sub_Folder (oFolder) Then
Cleanup_Sub_Folder = False
Exit Function
End If
Next

Cleanup_Sub_Folder = True
Exit Function
'
End Function

</pre>
 
D

Diana C Bouchard

I have been very happy with a product called Ultra Win Cleaner 2000 from
Business Logic Corporation (http://www.blcorp.com). It does various kinds
of Windows cleanup including registry, Internet junk, and *.TMP files (not
sure if it does *.BAK) on whatever drive letter you select, including all
subdirectories. They have an NT version.

Diana Bouchard

*******************************************************************
Diana C. Bouchard
Pulp and Paper Research Institute of Canada (Paprican)
Process Control Group
570 St Johns Boulevard
Pointe Claire Quebec H9R 3J9 Canada
phone: (514) 630 4100 x2376 fax: (514) 630 4120
email: [email protected]
******************************************************************
 
If your SCADA app can create these files in assorted directories, can't it run a "del *.bak" and "del *.tmp" on those same directories ?

Seems like a simple "timed rule" for most SCADA apps....

Mark Hill
Intelligent SCADA Solutions
Microsoft Associate Expert
 
P

Pierre Desrochers

We where told a simple command in DOS like "Erase c:\data01\*.tmp
............. and something to tell it to do this to all sub-d also ???
would do it but could it be this simple ?

Pierre Desrochers
Integral Instrumentation Inc
Montreal - Canada
 
P

Pierre Desrochers

<<If your SCADA app can create these files in assorted directories, can't it
<<run a "del *.bak" and "del *.tmp" on those same directories ?

It's not only the SCADA system creating the subs and .tmp files, it's many
other apps openning some files created by the SCADA.

We also have PE creating subs to back some special events, and this is OK
but we would like to get away with all those tmp and bak files... they
double the size of data on disk.

Pierre Desrochers
Integral Instrumentation Inc
Montreal - Canada
 
E
If you're running DOS 6.0 or later, you can use this command in a .bat file:

DELTREE [/Y] [d:]path [d:]path[...]

This will delete all files and subdirectories in the C:\Windows\Temp directory. (The /Y switch causes the command to run without prompting for
confirmation)

In my autoexec.bat file, I automatically remove all the "junk" that collects in the C:\windows/temp directory with this line:

DELTREE /Y C:\WINDOWS\TEMP\*.*

Works great! I hope this helps you!

See the description of this command at http://www.easydos.com/deltree.html

- Eric
[email protected]
Controls/Software
Packaging Associates Automation Inc. [email protected]
Rockaway, NJ, USA
 
Pierre;

Obviously, you need to know the location and extensions of all the files
to be deleted (erased), and if (sub)directories are to be deleted, their
location and name must be known.

Both del and erase perform the same functions as follows:

DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names

names Specifies a list of one or more files or directories.
Wildcards may be used to delete multiple files. If a
directory is specified, all files within the directory
will be deleted.

/P Prompts for confirmation before deleting each file.
/F Force deleting of read-only files.
/S Delete specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global
wildcard
/A Selects files to delete based on attributes attributes
R Read-only files S System files
H Hidden files A Files ready for
archiving
- Prefix meaning not

If Command Extensions are enabled DEL and ERASE change as follows:

The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.


A timed del or erase "rule" will remove anything from your HD.
I've done this in many SCADA apps with great success.

Mark Hill
Intelligent SCADA Solutions
Microsoft Associate Expert
 
P

Pierre Desrochers

< If you're running DOS 6.0 or later, you can use this command in a .bat
< file:

< DELTREE [/Y] [d:]path [d:]path[...]

-------------

<Is there a command in DOS or other (we use Win NT) where we could say once
a
<day start this batch file which would erase all those .TMP and .BAK files
in
<a directori ... INCLUDING those in all it's sub-directory...

The thing is we don't know the sub-directories names and we only want to
delete certain extensions in those...

Pierre Desrochers
Integral Instrumentation Inc.
Montreal - Canada
 
K
The rules seem to keep changing, but for some versions of
DOS/Windows I recall using 'deltree', and more recently 'del /s'
to delete directory trees. The latter (if available) should do
what you show above.

If Perl is available you might consider using its find()
command to walk the tree and delete each (selected) file.

--
Ken Irving <[email protected]>
 
J

John G. Boland

Hi, Pierre,

You write:

> Is there a command in DOS or other (we use Win NT) where we could say once
a
> day start this batch file which would erase all those .TMP and .BAK files
in
> a directori ... INCLUDING those in all it's sub-directory... we are
running
> out of space.

This might work for you, assuming the following directory structure:
d:\test00\ directory, containing
test00.txt
test00.csv
test00.crp
test01\ directory, containing
test01.txt
test01.csv
test01.crp
test02\ directory, containing
test02.txt
test02.csv
test02.crp
test0x.* are a one-word ("test") text file, copied and renamed with the
other extensions, just to have something to play with.

Follow the Windows NT Help instructions for commands, selecting "del". This
DOS session deletes ONLY the *.csv files in the test00\ directory and its
subdirectories:

C:\>d:

D:\>cd test00

D:\test00> del *.csv /s
Deleted file - D:\test00\test00.csv
Deleted file - D:\test00\test01\test01.csv
Deleted file - D:\test00\test01\test02\test02.csv

D:\test00>exit

The "/s" switch deletes corresponding files with the *.crp extension in
subdirectories, as shown above.

These DOS commands run in a batch file, too. Save a text file with the
following contents as "killCSV.bat":
d:
cd test00
del *.csv /s
exit

Make backup copies of the test directory test00 and run killCSV.bat. All
*.csv files will be gone.

Restore the test00 directory, open test01.csv in Excel(R), and run
killCSV.bat again. The test01.csv file will be left, but the other *.csv
files will be gone. In your case, the corresponding file will (probably) be
deleted the next time you run (schedule) killCSV.bat, since the application
that has the file open should have a different file open.

You may want to disable echo in the batch file (enable before exit) if the
deletes are extensive.

HTH, if I did not misunderstand your question.

Best,

John G. Boland, president
VisiBit Corporation
www.visibit.com
One Parker Square Suite 408
2525 Kell Boulevard
Wichita Falls, Texas 76308
940.322.9922
940.723.1478 fax
 
P

Pierre Desrochers

Thancks to all who have help us in solving this little painfull task.

Silly me, I was testing some suggestion on my Win98SE desktop... the /s switch did not work there but when tested on an NT system it worked fine.

So here it is :

D:\> del *.tmp /s ... command in a batch (.bat) file

erased all *.tmp files in this directorie AND also in all its sub-directories (/s)

Thancks again!

Pierre Desrochers
Integral Instrumentation Inc.
Montreal - Canada

 
Top