delete files from DOS

  • Hi,

    I need to delete all the files from a directory named c:\sgrs except Rar files (Rar is the extension). Need to accomplish this with a DOS command.

    I can do it in several steps like:

    step1 ) delete all files that are in the c:\sgrs folder (txt files and others)

    step2 ) delete all folders inside c:\sgrs (first have to delete all files from each folder)

    This is a multi step method.

    Is there any command in DOS where i can say directly to delete all that is inside c:\sgrs except .Rar files?

    Thank you

    Rate this post

  • if you're executing this within a sql server agent job i'd use a VB script

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • It's not a job. it's SQL. I need to use xp_cmdshell ( I know the security risks asociated with xp_cmdchell).

    Can someone help?

  • Are you running this ad hoc or are you going to schedule it?

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • ad hoc

  • try this link. It may be what you're after......

    Or, read the directory of files into a temp table, loop through that deleting the files (using xp_cmdshell) where [text] not like '%filename%'

    _________________________________________________________________________________SQLGeordieWeb:- Jarrin ConsultancyBlog:- www.chrisjarrintaylor.co.ukTwitter:- @SQLGeordie

  • Thanks, great help (the link).

    Best Regards,

    PR

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply