Page 1 of 2 12>
Topic Options
#198243 - 2010-03-29 10:47 PM Need help Deleting Files out of user profiles
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
I looked and looked for an existing script on this site but I could not find one. Does someone have a script that I can use that will delete the files out of each users profile on the Windows 2003 server.

In otherwords delete everything out of the following location...

Q:\Documents and Settings\userloginid\documentum\viewed


Thanks,
Syn


Edited by synwave7 (2010-03-29 10:48 PM)
_________________________
Bang that head that doesn't bang!!!

Top
#198248 - 2010-03-30 09:20 AM Re: Need help Deleting Files out of user profiles [Re: synwave7]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4615
Loc: The Netherlands
If this script should run as the currently logged on user then something like below should do the trick.

 Code:
Del "Q:\Documents And Settings\" + @USERID + "\documentum\viewed\*.*" /h
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#198250 - 2010-03-30 09:33 AM Re: Need help Deleting Files out of user profiles [Re: Mart]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
This script will look in every profile - you must have sufficient privilege of course:
 Code:
$sPrefix="Q:\Documents and Settings\"
$sSuffix="\documentum\viewed"

$sEntry=Dir($sPrefix+"*")
While Not @ERROR
	If Exist($sPrefix+$sEntry+$sSuffix)
		"Match found for user "+$sEntry+@CRLF
		; *** DO YOUR DELETE HERE ***
	EndIf
	$sEntry=Dir()
Loop


Just add your own DEL code when you are happy that it works.

Top
#198261 - 2010-03-30 03:08 PM Re: Need help Deleting Files out of user profiles [Re: Richard H.]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Thanks so much to both Mart and Richard H. for assisting me. I never was much good at this scripting stuff. Makes my brain hurt.

I am an administrator on the server I need to run this on. I tried Marts and it works well but I am going to run this myself periodically say once a month, off hours, until they move to another server with more space and they fix thier app to purge these files on a daily basis through the application itself.

Anyway, I'm not sure I understand how to do the DEL in the script Richard? You have
 Quote:
; *** DO YOUR DELETE HERE ***
in the script but I am not sure what to put thier? As I said initially I need to go through everyones profile in thier Q:\Documents and Settings\userid\documentum\viewed folder but not everyone will have the Documentum\Viewed and if they dont the script should skip that user and move onto to the next.

What do I input in the script to make it delete everything out of the users documentum\viewed directory?

I tried DEL *.* so in other words I changed the script to read...

 Code:
 $sPrefix="Q:\Documents and Settings\"
$sSuffix="\documentum\viewed"

$sEntry=Dir($sPrefix+"*")
While Not @ERROR
	If Exist($sPrefix+$sEntry+$sSuffix)
		"Match found for user "+$sEntry+@CRLF
		DEL *.*
	EndIf
	$sEntry=Dir()
Loop


The code appears to work (Loop) three times I get a 0 then another 0 then another 0 and finally on the first user profile the code errors out...the code gives me...

Match found for user asmith<unknown:CRLFScript error :expected expression.!

Thanks again for the assistance - please help.

Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198264 - 2010-03-30 03:28 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Gaaah! DEL *.* \:o

You must be the luckiest man alive, go buy a lottery ticket now!

Quite how you got away with not seriously damaging the local machine I don't know.

I left the DEL out so that there was no risk to your system in case my coding had unexpected results. The full code (including the delete) would be:
 Code:
$sPrefix="Q:\Documents and Settings\"
$sSuffix="\documentum\viewed"

$sEntry=Dir($sPrefix+"*")
While Not @ERROR
	If Exist($sPrefix+$sEntry+$sSuffix)
		"Match found for user "+$sEntry+@CRLF
		; Here comes the delete, commented out.
		; Remove the ";" character from the line below to enable the delete code.
		;Del $sPrefix+$sEntry+$sSuffix+"/*.*"
	EndIf
	$sEntry=Dir()
Loop


Run the script as-is to check that the script correctly identifies direcorties to clean up.

When you are happy with that uncomment the Del line by removing the ";" character.

Top
#198265 - 2010-03-30 03:31 PM Re: Need help Deleting Files out of user profiles [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
BTW, what version of KiXtart are you running - you shouldn't have had any problem with the @CRLF macro.
Top
#198266 - 2010-03-30 03:34 PM Re: Need help Deleting Files out of user profiles [Re: Richard H.]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Richard,
I'm sure it's quite old, now that you mention it, I am updating to the latest now and will let you know what I come up with. Thanks.

Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198267 - 2010-03-30 03:35 PM Re: Need help Deleting Files out of user profiles [Re: Richard H.]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4615
Loc: The Netherlands
 Originally Posted By: Richard H.
Gaaah! DEL *.* \:o

You must be the luckiest man alive, go buy a lottery ticket now!
....


LOL del *.* might not be the best option here

Putting in a small line that displays stuff on the console window will show you what will happen when you run the script with the actual delete command enabled but it does not delete anything yet.

 Code:
$sPrefix="Q:\Documents and Settings\"
$sSuffix="\documentum\viewed"

$sEntry=Dir($sPrefix+"*")
While Not @ERROR
	If Exist($sPrefix+$sEntry+$sSuffix)
		"Match found for user "+$sEntry+@CRLF
		; Here comes the delete, commented out.
		; Remove the ";" character from the line below to enable the delete code.
		;Del $sPrefix+$sEntry+$sSuffix+"/*.*"
		?"Pretending to delete files from: " + $sPrefix + $sEntry + $sSuffix
	EndIf
	$sEntry=Dir()
Loop
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#198268 - 2010-03-30 03:37 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Richard,
Was I putting the correct syntax in the code to delete everything out of the documentum\viewed folder?

Thanks,
Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198269 - 2010-03-30 03:43 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Richard,
I upgraded to 4.61 I can update to the latest if needed I just happened to already have 4.61 downloaded.

The code works like a charm now except I ran the code in debug and normal and I see it working fine. I still dont know what to add in order to make it delete though?

Sorry for the confusion. Please advise.

Thanks,
Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198270 - 2010-03-30 03:47 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Richard and Mart,
Oops I did not see Mart's reply until now. Thanks Mart LOL...I was in debug mnode LOL....

I see the correct code to delete now I will try and let you know.

You guys are Beautiful!!

Much Thanks,
Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198271 - 2010-03-30 03:56 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Richard and Mart,
Excellent! If I may be greedy for a minute is there a way to make it show or confirm that it actually deleted something. You know for a dummy like me I just like to see the result if you will...I double checked the directories visually for a few users and it did of course work most excellent.

Thanks,
Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198272 - 2010-03-30 04:00 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4615
Loc: The Netherlands
 Originally Posted By: synwave7

....
I was in debug mnode LOL
....

Files will still get deleted if you are in debug mode.
Debug mode does not prevent any code form running it just shows you line by line what it is doing.

 Originally Posted By: synwave7

....
You guys are Beautiful!!
....

Thatís what I tell myself every morning when Iím just out of bed and look in the mirror \:D
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#198273 - 2010-03-30 04:05 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4615
Loc: The Netherlands
 Originally Posted By: synwave7
Richard and Mart,
Excellent! If I may be greedy for a minute is there a way to make it show or confirm that it actually deleted something. You know for a dummy like me I just like to see the result if you will...I double checked the directories visually for a few users and it did of course work most excellent.

Thanks,
Syn


Sure.
You can change the code a bit (one line before and one line after the delete) to show you what happened while deleting files.

 Code:
? "Deleting files from folder: " + $sPrefix + $sEntry + $sSuffix
;Del command goes here
? "Result of deleting files: " + @ERROR + " - " + @SERROR
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#198274 - 2010-03-30 04:19 PM Re: Need help Deleting Files out of user profiles [Re: Mart]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Mart,
Sweet, good enough thanks so very much to you both!!!!

Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198275 - 2010-03-30 04:20 PM Re: Need help Deleting Files out of user profiles [Re: Mart]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
It actually takes quite a bit more code if you want detail about what has been deleted. The sample below lists each file and attempts to delete it in turn, displaying the success/failure for each attempt.

This code will of course execute more slowly, which may or may not be significant depending on the number of users concerned.

 Code:
$=SetOption("WrapAtEOL","ON")
$sPrefix="Q:\Documents and Settings\"
$sSuffix="\documentum\viewed\"

$sEntry=Dir($sPrefix+"*")
While Not @ERROR
	If Exist($sPrefix+$sEntry+$sSuffix)
		"Match found for user "+$sEntry+@CRLF
		$sFileToDelete=Dir($sPrefix+$sEntry+$sSuffix+"*.*",1)
		While Not @ERROR
			If Not (16 & GetFileAttr($sPrefix+$sEntry+$sSuffix+$sFileToDelete))
				" Deleting file: "+$sFileToDelete+", RESULT: "
				Del $sPrefix+$sEntry+$sSuffix+$sFileToDelete
				IIF(@ERROR,"FAILED with error ["+@ERROR+"] "+@SERROR,"Success")+@CRLF
			EndIf
			$sFileToDelete=Dir(,1)
		Loop
	EndIf
	$sEntry=Dir()
Loop

Top
#198276 - 2010-03-30 04:32 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
I notice I am getting access denied when running with the results. If I use Windows Explorer and navigate to the dir I can delete the files just fine? Does kix32.exe need a switch in order to run as an admin? I am running the kix32.exe as myself and I am an admin on the box? Can you please advise as to why kix32.exe is getting access denied?

Thanks,
Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198277 - 2010-03-30 04:36 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
KiXtart will use your current login and privilege.

Maybe something trickier is happening - are the files local to the server or on a share? Are they in use? Which version of the code are you trying, Mart's or my latest one posted above that enumerates and removes the files individually?

Top
#198278 - 2010-03-30 04:57 PM Re: Need help Deleting Files out of user profiles [Re: Richard H.]
synwave7 Offline
Fresh Scripter

Registered: 2002-01-27
Posts: 49
Loc: Chicago, IL. 60601
Richard,
Most excellent on both scripts. I tried both and they both give the access is denied error for the files. As I said when I manually go to the directories in Windows and delete the files I can delete them successfully. To answer your questions...

1. Are the files local to the server or on a share? The files are local to the server.

Are they in use? I thought of that and made sure they are/were not.

3. Which version of the code are you trying, Mart's or my latest one posted above that enumerates and removes the files individually? I tried both.

Syn
_________________________
Bang that head that doesn't bang!!!

Top
#198280 - 2010-03-30 05:07 PM Re: Need help Deleting Files out of user profiles [Re: synwave7]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Hmmm... could be some sort of redirection going on.

  • What version of Windows is the server running?
  • Is it 32 or 64 bit?
  • Could you copy and paste a sample from the command line window, it might help to see some of the output (a dozen lines or so will do).


I'm finishing for the day, so if no-one else comes up with anything I'll take a look again tomorrow (~08:00 BST)

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
4 registered (Jochen, AndreLuiz, Flavien, Arend_) and 206 anonymous users online.
Newest Members
Sjaak, Biybucket, Markus1961, Ian231, kixnewbie12
17480 Registered Users

Generated in 0.084 seconds in which 0.029 seconds were spent on a total of 14 queries. Zlib compression enabled.

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