![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Deleting Contents of Folder Would anybody give me some direction on generating a script that would scroll through a drive on a server and delete the contents of a users folder (leave the folder there) if the folder hasn't been accessed in a certain ammount of time? Location example: d:\users\USERNAME |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Deleting Contents of Folder "Jason Carter" <JasonCarter@xxxxxx> wrote in message news:7BA18BD6-34D8-48D0-A604-2C8C3C480D41@xxxxxx
wrote anything to the folder then you can use something like this: $UserDir = d:\users\<username> $DateLimit = (get-date).AddDays(-30) $newItems = Get-ChildItem $UserDir\* -rec | Where {$_.LastWriteTime -gt $DateLimit} if (!$newItems) { remove-item $UserDir\* -r -whatif } Remove the -whatif to actually do the delete. -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Deleting Contents of Folder Thats what I meant. Thanks a lot. Is there anyway you can do this without specifying the username? Just process the whole Users directory with this script for each folder? "Keith Hill [MVP]" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Deleting Contents of Folder Using the * will do this correct: d:\users\* ? "Jason Carter" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: Deleting Contents of Folder "Jason Carter" <JasonCarter@xxxxxx> wrote in message news:C984DEA3-CC62-4758-9592-C66841318909@xxxxxx
-- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Deleting Contents of Folder "Keith Hill [MVP]" <r_keith_hill@xxxxxx_spam_I> wrote in message news:B81EBA3C-33AB-47E1-BBC3-C17EF2F3394B@xxxxxx
$DateLimit = (get-date).AddDays(-30) foreach ($UserDir in (get-childitem d:\users | where {$_.PSIsContainer})) { $newItems = Get-ChildItem $UserDir -rec | Where {$_.LastWriteTime -gt $DateLimit} if (!$newItems) { remove-item $UserDir\* -r -whatif } } -- Keith | ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Deleting Contents of Folder Alright thanks. And now I am starting to understand this stuff by looking at some code. "Keith Hill [MVP]" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #8 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Deleting Contents of Folder I am going to try to modify it to delete subfolders too. "Keith Hill [MVP]" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #9 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Deleting Contents of Folder In testing, what I am seeing here is that all the sub files are getting deleted, which are making the sub folders last write time change so the actually subfolders are not getting deleted if they are present. Would I add a remove-item $UserDir\*\* -force at the end? "Jason Carter" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #10 (permalink) | ||||||||||||
| Guest | Re: Deleting Contents of Folder "JSC" <JSC@xxxxxx> wrote in message news:B71B370C-D031-4DFF-B0A0-F6784A755286@xxxxxx
use -force just to take care of any read-only files. -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| moving folder contents to a new folder | A | Live Folder Share | 1 | 05-25-2008 03:56 AM |
| Deleting System Volume Information contents in Vista | User66 | Vista installation & setup | 4 | 05-20-2008 01:49 PM |
| Deleting SpamKiller Contents | rdrunners2 | Vista mail | 4 | 11-01-2007 06:16 PM |
| Temp dir - deleting contents on shutting down | Dave Horne | Vista General | 13 | 05-02-2007 07:31 AM |
| Access folder contents | Scott | Vista General | 3 | 02-17-2007 06:37 PM |