Page 1 of 1 1
Topic Options
#160378 - 2006-04-05 03:46 PM Directory Listing for Deletion
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
Good morning,

Our logon script copies the contents of a directory (based upon group) to a user's desktop when the user logs in. When the user logs out my boss wants the files to be deleted off of the desktop so that there is less cleanup if we need to change a users group. That being said, how would I read the contents of a directory (including directories) into an array and delete each file and directory in the top-level directory? Thanks in advance!

Hoopes

Top
#160379 - 2006-04-05 03:49 PM Re: Directory Listing for Deletion
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Have a look at the DirPlus() UDF. It works great, I use it all the time.

DirPlus() - a recursive dir tool
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#160380 - 2006-04-05 04:29 PM Re: Directory Listing for Deletion
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
Cool that worked great! One last question how do I delete a directory?
Top
#160381 - 2006-04-05 04:38 PM Re: Directory Listing for Deletion
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
RD
Action: Removes the directory specified.

Syntax: RD "directory"

Remarks:

The directory must be empty for this command to succeed.

Check the value of @ERROR to see if RD was successful.

See Also:

CD, Copy, Del, MD
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#160382 - 2006-04-05 05:37 PM Re: Directory Listing for Deletion
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
I thought that was my last question. How do I get DirPlus() to only display the file or directory name instead of the entire path?
Top
#160383 - 2006-04-05 06:28 PM Re: Directory Listing for Deletion
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
Here's what I have so far: ($FILE and $DIRECTORY are returing the whole path instead of just the file or directory name)

Code:

select
case ingroup("dmlcl_grp_mis_APPS")
$DMLCL_GRP_APPS_MAIN_FOLDER = "mis"
case ingroup("dmlcl_grp_acct_APPS")
$DMLCL_GRP_APPS_MAIN_FOLDER = "acct"
endselect

; Delete dmlcl_grp_*_APPS Related Apps and Documents on User's Desktop
cd "$DC\$SHORTCUTS\$DMLCL_GRP_APPS_MAIN_FOLDER"
$DMLCL_GRP_APPS_FILES = dirplus(".")
for each $FILE in $DMLCL_GRP_APPS_FILES
del "$DC\Users\@USERID\Desktop\$FILE" /s
del "$DC\Users\@USERID\Application Data\Microsoft\Internet Explorer\Quick Launch\$FILE" /s
? "Deleted File: " $FILE
next

; Delete dmlcl_grp_*_APPS Related Folders on User's Desktop
$DMLCL_GRP_APPS_DIRECTORIES = dirplus(".")
for each $DIRECTORY in $DMLCL_GRP_APPS_DIRECTORIES
? "Current Dir: " @CURDIR
rd "$DC\Users\@USERID\Desktop\$DIRECTORY"
rd "$DC\Users\@USERID\Application Data\Microsoft\Internet Explorer\Quick Launch\$DIRECTORY"
? "Deleted Directory: " $DIRECTORY
next


Top
#160384 - 2006-04-05 06:39 PM Re: Directory Listing for Deletion
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This will get you just the path and/or filename without the c:\documents and settings…bla..bla..bla....desktop\ part. Only the part of the path dirplus gives you starting at the folder you made on the users desktop.

Code:

$location = %userprofile% + "\desktop\folder"
$lenght = Len ($location) + 2

$stuff = DirPlus($location,"/s")

For Each $thing in $stuff
$name = SubStr($thing, $lenght)
?$name
Sleep 1
Next



Don't forget to include dirplus somewhere in your script. But I guess you know that already.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#160385 - 2006-04-05 06:47 PM Re: Directory Listing for Deletion
hoopes Offline
Fresh Scripter

Registered: 2006-03-02
Posts: 33
You're awesome! Thanks for eveyone's help!
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 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.056 seconds in which 0.024 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