Page 1 of 1 1
Topic Options
#60144 - 2001-10-30 05:54 AM When the folder is empty, the script hangs
Anonymous
Unregistered


Hi Bryce,

I am using your script and I want to delete the files in some folders. I find your script is great. I have make a little change in your script such that I can del the "recent" and "favorites" files in user profiles, like this

change %temp% ==> %userprofile%
and I use a variable, say, $fav and $rec
$fav = %userprofile% + "\favorites"
$rec = %userprofile% + "\recent"

But it is not the main point, I want to says is the first time the script run excellent. When I run the second time, so no file or directory in it, the script continue to loop and did not stop.

Thanks for your concern!

Gilbert Ng

------------------------------------------
break on cls

$tempdir = "temp1.dat"
$tempfile = "temp2.dat"
dim $tempdir_data[99999]

:wrong
? "This will Delete all files and Directories in"
? "%temp%!!! are you sure?(y/n)"
get $yn
select
case lcase($yn) = "y"
;run rest of code
case lcase($yn) = "n"
exit
case 1
goto wrong
endselect


shell "%comspec% /c dir %temp% /ad /b /s > $tempdir"
shell "%comspec% /c dir %temp% /a-d /b /s > $tempfile"

? "Deleting the files in %temp%" gosub kill_files
? "Removing all Directories in %temp%" gosub Kill_directories

del $tempdir
del $tempfile
exit


;----------------------------
:Kill_Files
;----------------------------

$q = open(1,$tempfile)
$tempfile_data = readline(1)
while @error = 0
del $tempfile_data
$tempfile_data = readline(1)
loop
$q = close(1)
return

;----------------------------
:Kill_directories
;----------------------------
$array_count = 0
$q = open (1,$tempdir)
$tempdir_data[$array_count] = readline(1)

while $tempdir_data[$array_count] <> ""
$array_count = $array_count + 1
$tempdir_data[$array_count] = readline(1)
loop
$q = close(1)

rd $tempdir_data[$array_count]
while $array_count >= 0
rd $tempdir_data[$array_count]
$array_count = $array_count - 1
loop
return
-------------------------------------------

Top
#60145 - 2001-10-30 03:47 PM Re: When the folder is empty, the script hangs
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Gilbert,

Can I interrupt here?

The original...

code:

rd $tempdir_data[$array_count]
while $array_count >= 0
rd $tempdir_data[$array_count]
$array_count = $array_count - 1
loop
return

Can you change it to?

code:

while $array_count >= 0
rd $tempdir_data[$array_count]
$array_count = $array_count - 1
loop
return

In other words, you want to test if the $array_count >= 0 and if it meets that condition, then remove the directory.

Back to your lesser point:

quote:

$fav = %userprofile% + "\favorites"
$rec = %userprofile% + "\recent"

Why don't you use?

$fav = READVALUE("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","favorites")
$rec = READVALUE("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","recent")

This way, you don't have be dependent on Environment variables and these keys are consistent whether it is 9x/NT/2k.

HTH,

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#60146 - 2001-10-30 09:45 PM Re: When the folder is empty, the script hangs
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Why not using the deltree command?

Reading the information from a file is much slower. You think the amount of files can be
very big (see array size of 99.999 elements).
Files with special attributes (line: ReadOnly) will not removed by del or rd commands.
First you need to change those file attributes.
For W9x systems you had also to deal with the known problem of flushing
write-buffers to your disk.

deltree doesn't have problems with special file attributes, flushing buffer
problem within w9x environments and can bypass possible open files.

Our version:

code:

CLS
BREAK ON
:wrong
? "This will Delete all files and Directories in"
? "%temp%!!! are you sure?(y/n)"
GET $yn
SELECT
CASE (LCase($yn) = "y")
;run rest of code
CASE (LCase($yn) = "n")
EXIT
CASE 1
GOTO wrong
ENDSELECT
SHELL '%comspec% /c deltree /y %temp%\.'
IF (Exist(%temp%) = 0)
MD %temp%
ENDIF

See our script cleanup.kix for other ideas about cleaning an user environ-
ment.
greetings.

btw: deltree program and cleanup.kix script you can find on
our site http://home.wanadoo.nl/scripting

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#60147 - 2001-10-30 10:21 PM Re: When the folder is empty, the script hangs
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I would go with MCA's idea, much faster

That bit of code that i made was really nothing more than a proof of concept.

Top
#60148 - 2001-10-31 04:42 AM Re: When the folder is empty, the script hangs
Anonymous
Unregistered


Thanks to you all,

I will try it.

Gilbert Ng

Top
#60149 - 2001-10-31 10:04 AM Re: When the folder is empty, the script hangs
Anonymous
Unregistered


I use also Bryce's script and for me it works fine and fast. In NT/Win2k it's more difficult to do the thing that "deltree /y" does, because this util does not exist in NT/Win2k.

Here's the script I use:

code:

$userTempDirectories = "userTempDirectories.txt"
$userTempFiles = "userTempFiles.txt"
Dim $tempdir_data[99999]

Shell "%comspec% /c attrib -h -r %temp%\*.* /s /d"
Shell "%comspec% /c dir %temp% /ad /b /s > $userTempDirectories"
Shell "%comspec% /c dir %temp% /a-d /b /s > $userTempFiles"

Gosub deleteUserTempFiles
Gosub deleteUserTempDirectories

:deleteUserTempFiles
$q = Open(1,$userTempFiles)
$tempfile_data = ReadLine(1)
While @ERROR = 0
Del $tempfile_data
$tempfile_data = ReadLine(1)
Loop
$q = Close(1)
Del $userTempFiles
Return

:deleteUserTempDirectories
$array_count = 0
$q = Open (1,$userTempDirectories)
$tempdir_data[$array_count] = ReadLine(1)
While $tempdir_data[$array_count] <> ""
$array_count = $array_count + 1
$tempdir_data[$array_count] = ReadLine(1)
Loop
$q = Close(1)
Rd $tempdir_data[$array_count]
While $array_count >= 0
Rd $tempdir_data[$array_count]
$array_count = $array_count - 1
Loop
Del $userTempDirectories
If Exist ("%temp%") = 0
Md "%temp%"
EndIf
Return
Exit


I"n some cases the temp-dis were also removed, so I added a check to see if the dir exist, and if not, make that dir again.

Martijn

Top
#60150 - 2001-10-31 05:07 PM Re: When the folder is empty, the script hangs
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
What about :

shell '%ComSpec% /C RD [/S] [/Q] [drive:]path' ???

works on NT and 2k !

J.

_________________________



Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.065 seconds in which 0.036 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org