Home All Groups Group Topic Archive Search About

Batch file to delete files dynamically

Author
20 Jan 2009 12:27 AM
freelancer24
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-development/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 ------------------------------------------------------------------------ freelancer24's Profile: http://forums.techarena.in/members/freelancer24.htm View this thread: http://forums.techarena.in/server-scripting/1106128.htmhttp://forums.techarena.in

Author
20 Jan 2009 7:07 AM
Pegasus (MVP)
Show quote Hide quote
"freelancer24" <freelancer24.3maffc@DoNotSpam.com> wrote in message
news:freelancer24.3maffc@DoNotSpam.com...
>
> 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-development/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.
Author
20 Jan 2009 1:44 PM
Al Dunbar
Show quote Hide quote
"Pegasus (MVP)" <I.***@fly.com.oz> wrote in message
news:%23IG8N3seJHA.5748@TK2MSFTNGP03.phx.gbl...
>
> "freelancer24" <freelancer24.3maffc@DoNotSpam.com> wrote in message
> news:freelancer24.3maffc@DoNotSpam.com...
>>
>> 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-development/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

Show quoteHide quote
>> --
>> 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.
>
Author
7 Feb 2009 9:03 PM
Patrick Mc
I am a system admin. Instead of using MS DOS batch file, I use biterscripting script. I can do any dynamic/batch/bulk copy-move-delete-create-rename-or any other operation on files from biterscripting. This script can be called right from within a web server, another program, dos prompt, task scheduler, etc. I think the following commands will be useful for you -

lf - list files
af - access file (sets various file parms that can be used to list files only if certain conditions are met)
system - send a command to system
stex, lex, wex, chex - string, line, word and character extractors (editors)

After downloading biterscripting free at http://www.biterscripting.com, do a help on these commands to get started. -- Patrick Mc ------------------------------------------------------------------------ Patrick Mc's Profile: http://forums.techarena.in/members/patrick-mc.htm View this thread: http://forums.techarena.in/server-scripting/1106128.htmhttp://forums.techarena.in