#198250 - 2010-03-30 09:33 AM
Re: Need help Deleting Files out of user profiles
[Re: Mart]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This script will look in every profile - you must have sufficient privilege of course:
$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
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 ; *** 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...
$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
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Gaaah! DEL *.*
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:
$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
|
|
|
|
#198275 - 2010-03-30 04:20 PM
Re: Need help Deleting Files out of user profiles
[Re: Mart]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
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.
$=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
|
|
|
|
#198280 - 2010-03-30 05:07 PM
Re: Need help Deleting Files out of user profiles
[Re: synwave7]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|