Page 1 of 1 1
Topic Options
#26628 - 2002-08-07 05:09 PM Using DIR
Anonymous
Unregistered


I trying to develope a script that will scan a specified folder and all of its sub folders for a file (portal.lnk) and if found del that file. Does any one have any ideas on how to do this.
Top
#26629 - 2002-08-07 05:28 PM Re: Using DIR
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Yes.
This works for Windows 2000/XP, might work for Windows NT/9x (check command line siwtches for DEL)
code:
$file=''c:\documents and settings\portal.lnk'
shell 'DEL /S /F /Q '+$file

_________________________
There are two types of vessels, submarines and targets.

Top
#26630 - 2002-08-07 05:41 PM Re: Using DIR
Anonymous
Unregistered


That will work on nt and w2k only, I still have over 1000 98 machines, some with profiles and some without.
Top
#26631 - 2002-08-07 05:44 PM Re: Using DIR
Anonymous
Unregistered


oh yeah I also forgot It might not be called portal.lnk but contain portal somwhere.

I was going to use INSTR("$FILENAME","PORTALG") <> 0 to search for the name.

Top
#26632 - 2002-08-07 05:49 PM Re: Using DIR
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Then you will need to use the DIR function and enumerate all files/folder. Detect a folder by looking at GETFDILEATTR() & 16, do an IF EXIST('*portal*.lnk') and if true do an DEL '*portal*.lnk', then move on to the next folder /subfolder.

Take a look at the DIR UDFs that are posted in the UDF forum or take a look at the CleanTempFiles() UDF which would also do what you want.
_________________________
There are two types of vessels, submarines and targets.

Top
#26633 - 2002-08-07 06:53 PM Re: Using DIR
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
something like:
dir /s |find "portal"|find ".lnk" > %temp%\portals.txt

then from there you can make a destroyal.
_________________________
!

download KiXnet

Top
#26634 - 2002-08-07 07:28 PM Re: Using DIR
Anonymous
Unregistered


YOU WILL ALSO HAVE PROBLEMS USING | IN ALL THE OS'S winnt will do strange things.

I am really looking for a a good recursion script or a way that is done that will open a folder search within if it finds a file delete it if not go to next folder and so on and so on.

Top
#26635 - 2002-08-07 07:48 PM Re: Using DIR
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Have you taken a look at the CleanTempFiles() UDF? This can be used to delete any file in any folder based on wildcards and/or dates
_________________________
There are two types of vessels, submarines and targets.

Top
#26636 - 2002-08-07 08:03 PM Re: Using DIR
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens correct if I'm wrong with this but couldn't he use deltree?
create a file in the c:\ with name of portal.lnk
and then call deltree:
deltree c:\*portal*.lnk

don't know what switches are needed, but...
I think mca wrote on some similar topic that it will do the trick.
_________________________
!

download KiXnet

Top
#26637 - 2002-08-07 08:20 PM Re: Using DIR
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jooel,
You don't need to create it in the root for that to work. For example, I use the following code to search for a specific file and then delete the parent folder.
code:
:CLEANUP

SHELL "%COMSPEC% /C dir /b /s C:\unpatch.bak > C:\out.txt"

IF GetFileSize("C:\out.txt") > 0

IF OPEN(1, "C:\out.txt") = 0
$cl = ReadLine(1)

WHILE @ERROR = 0
$ncl = SUBSTR($cl, 1, LEN($cl) - 12)

if SUBSTR($ncl, LEN($ncl)-5, LEN($ncl)) = "Backup"
SHELL "deltree /Y " + CHR(34) + $ncl + CHR(34)
ENDIF
$cl = ReadLine(1)

LOOP
ENDIF
$_ = CLOSE(1)
ENDIF

DEL "C:\out.txt"

Of course I'd do it differently now that I'm so much smarter. [Wink]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#26638 - 2002-08-07 08:47 PM Re: Using DIR
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yeah, like... your script looks a lot more difficult than just creating a file and deleting with mask in the whole drive...
_________________________
!

download KiXnet

Top
#26639 - 2002-08-07 09:36 PM Re: Using DIR
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Guys, he just want to delete the file not the whole folder!
_________________________
There are two types of vessels, submarines and targets.

Top
#26640 - 2002-08-07 09:51 PM Re: Using DIR
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens, I guess we know.
maybe...
anyway with deltree you can do a file delete in directory structure.
and that file does not have to be with same name.
you can mask it.
sounds too simple but that's the way it is.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1821 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.071 seconds in which 0.035 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