|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 *** 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 |
||||||||
|
|
|||||||
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: 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. |
||||||||
|
|
|||||||
BTW, what version of KiXtart are you running - you shouldn't have had any problem with the @CRLF macro. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Originally Posted By: Richard H. Gaaah! DEL *.* 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 |
||||||||
|
|
|||||||
Richard, Was I putting the correct syntax in the code to delete everything out of the documentum\viewed folder? Thanks, Syn |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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, Sweet, good enough thanks so very much to you both!!!! Syn |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Hmmm... could be some sort of redirection going on.
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) |
||||||||
|
|
|||||||
Yes, perhaps your partially correct but not redirection. Theres no roaming profiles, no redirection of any of the profile. HOWEVER - we remap the boot (hard) drive(s). So, in other words rather than C: drive and D: drive we remap C: drive to Q: drive and D: drive to R: drive 1. Windows 2003 SP2 2. 32 bit 3. I get a lot of "Deleting file: filenamehere.pdf, RESULT: FAILED with error [5] Access is denied." over and over for each and every file the code finds. Syn |
||||||||
|
|
|||||||
Presumably when you delete one of these files through explorer you don't get a prompt (other than the basic "are you sure"). A couple of things to try: Take one of the files that is failing, open a command prompt and try to delete it using the full path, see if the delete works at the command line. Try adding the "force" flags to the del command and see if it helps: Code: Del $sPrefix+$sEntry+$sSuffix+$sFileToDelete /f /h If that doesn't work then maybe follow the path of least resistance and get the users to delete their own files in their startup script. |
||||||||
|
|
|||||||
Richard, Ahh yes the /f switch worked like a charm. All is good now. Sorry for the confusion I should have thought of that. Thanks again and again and again to you and Mart for the help!!!! Syn |