Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Batch file to delete files dynamically

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 20-01-2009
Member
 
Join Date: Jan 2009
Posts: 1
Batch file to delete files dynamically

Hello All,

I read the threads here but they did not quite answer my question:
http://forums.techarena.in/server-scripting/1062489.htm
Create a batch (. Bat) MS-DOS to delete files
Creating a batch file to find and delete certain files

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 !!

Reply With Quote
  #2  
Old 20-01-2009
Pegasus \(MVP\)
 
Posts: n/a
Re: Batch file to delete files dynamically


"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
> Create a batch (. Bat) MS-DOS to delete files
> Creating a batch file to find and delete certain files
>
> 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
  #3  
Old 20-01-2009
Al Dunbar
 
Posts: n/a
Re: Batch file to delete files dynamically


"Pegasus (MVP)" <I.can@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
>> Create a batch (. Bat) MS-DOS to delete files
>> Creating a batch file to find and delete certain files
>>
>> 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
  #4  
Old 08-02-2009
Member
 
Join Date: Feb 2009
Posts: 1
Re: Batch file to delete files dynamically

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.
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Batch file to delete files dynamically"
Thread Thread Starter Forum Replies Last Post
Creating a batch file to find and delete certain files Damien25 TroubleShoot 98 3 11-01-2014 09:58 AM
Create a batch (. Bat) MS-DOS to delete files Aarya Software Development 9 08-09-2011 12:58 AM
Need batch file to delete user files in Windows XP mcamp32 Windows XP Support 1 26-05-2011 10:54 PM
Dos batch file to sort files based on file names. Jon Osborn Windows Server Help 9 17-06-2009 11:06 AM
Batch Commands To Read and Delete Lines from txt-File officer07 Windows Server Help 3 04-03-2009 12:49 PM


All times are GMT +5.5. The time now is 11:25 PM.