Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Batch file to delete files dynamically

Reply
Thread Tools Display Modes

Re: Batch file to delete files dynamically

 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      01-20-2009

"freelancer24" <> wrote in message
news:...
>
> Hello All,
>
> I read the threads here but they did not quite answer my question:
> http://forums.techarena.in/server-scripting/1062489.htm
> http://forums.techarena.in/software-...nt/1098714.htm
> http://forums.techarena.in/troubleshoot-98/1072126.htm
>
> Here is what i accomplish to do with Windows 2003 Server running Active
> Directory. Create a batch file that will:
>
> 1) Find and delete all .prn files from servername\drive
> D:\data\users\xxxxxx\Print\ (where xxxx is the user name - there are 500
> users approx)
>
> Note: The parent directory keeps changing - xxxx - the user name but
> files have to be only deleted from the Print sub-directory from EACH
> users directory
>
> 2) Can this batch file be triggered when each user logs off - to clear
> the users .prn files ?
>
> I know this can be accomplished through publishing Group Policy on the
> domain in AD but i want to go through the batch file way.
>
> Is this possible?? Thanks a lot in advance. Cheers !!
> --
> freelancer24
>


Try this two-liner:
@echo off
for /F "delims=" %a in ('dir /ad /b
"\\servername\d$\data\users\xxxxxx\Print\"') do echo del /s "%%a\*.prn"

Remove the word "echo" in line 2 to activate the batch file.
You can trigger the batch file to run at shut-down time by a local policy or
by GPO.


 
Reply With Quote
 
 
 
 
Al Dunbar
Guest
Posts: n/a

 
      01-20-2009

"Pegasus (MVP)" <> wrote in message
news:%...
>
> "freelancer24" <> wrote in message
> news:...
>>
>> Hello All,
>>
>> I read the threads here but they did not quite answer my question:
>> http://forums.techarena.in/server-scripting/1062489.htm
>> http://forums.techarena.in/software-...nt/1098714.htm
>> http://forums.techarena.in/troubleshoot-98/1072126.htm
>>
>> Here is what i accomplish to do with Windows 2003 Server running Active
>> Directory. Create a batch file that will:
>>
>> 1) Find and delete all .prn files from servername\drive
>> D:\data\users\xxxxxx\Print\ (where xxxx is the user name - there are 500
>> users approx)
>>
>> Note: The parent directory keeps changing - xxxx - the user name but
>> files have to be only deleted from the Print sub-directory from EACH
>> users directory


If you run Pegasus' solution while logged on to one system with an account
that is an administrator on another you can delete all such files remotely.
This would be the best method if your goal is to periodically clean things
up.

>> 2) Can this batch file be triggered when each user logs off - to clear
>> the users .prn files ?


Well, this particular batch file would fail to delete anything if run as-is
as a logoff script, unless the user was an administrator on the box. Thie
might be a better approach if there is some aspect of security or privacy
involved, as it would delete the files as soon as feasible.

>> I know this can be accomplished through publishing Group Policy on the
>> domain in AD but i want to go through the batch file way.
>>
>> Is this possible?? Thanks a lot in advance. Cheers !!



We run a script to delete certain files from the current user's profile in a
logoff script that is run through a GPO. I'd think that if you can create a
policy to accomplish this without having to rely on a script, that would be
a cleaner solution.

Don't forget, though, that logoff scripts rely on the system still running.
If a user powers the system off ungracefully or the power fails, well, it
just won't happen that time.

/Al

>> --
>> freelancer24
>>

>
> Try this two-liner:
> @echo off
> for /F "delims=" %a in ('dir /ad /b
> "\\servername\d$\data\users\xxxxxx\Print\"') do echo del /s "%%a\*.prn"
>
> Remove the word "echo" in line 2 to activate the batch file.
> You can trigger the batch file to run at shut-down time by a local policy
> or by GPO.
>



 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch Commands To Read and Delete Lines from txt-File officer07 Windows Server 3 03-04-2009 06:19 AM
Batch file - specify which cookies to save and delete all others Bob Windows Vista General Discussion 0 02-05-2008 03:04 PM
Re: Batch file delete of unmatched files? Owen Williams [SBS MVP] Windows Small Business Server 2 02-06-2007 07:37 PM
Re: Batch File to delete existing shortcuts Jerold Schulman Scripting 0 05-26-2006 12:05 PM
Using Batch Files to delete text file on root of c: Nate B. Windows Server 1 04-11-2006 10:10 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59