Results 1 to 4 of 4

Thread: Batch file to delete files dynamically

  1. #1
    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 !!

  2. #2
    Pegasus \(MVP\) Guest

    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.



  3. #3
    Al Dunbar Guest

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




  4. #4
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,890,120.59400 seconds with 17 queries