+ Post New Thread
Results 1 to 14 of 14
Scripts Thread, Empty the contents of a folder in Coding and Web Development; Please can somone isnstruct me on a script that will empty the contents of a folder but not the folders ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196

    Empty the contents of a folder

    Please can somone isnstruct me on a script that will empty the contents of a folder but not the folders itself.

    Cheers

  2. #2

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,271
    Blog Entries
    2
    Thank Post
    595
    Thanked 877 Times in 615 Posts
    Rep Power
    277
    What language?

  3. #3

    Dos_Box's Avatar
    Join Date
    Jun 2005
    Location
    Preston, Lancashire
    Posts
    7,693
    Blog Entries
    21
    Thank Post
    197
    Thanked 1,412 Times in 580 Posts
    Rep Power
    357
    Ooh! Choice. Swahili please

  4. #4
    tonyd's Avatar
    Join Date
    Mar 2006
    Location
    Kent (Sometimes), UK
    Posts
    149
    Thank Post
    17
    Thanked 41 Times in 30 Posts
    Rep Power
    19
    Making the assumption we're talking about a windows machine, then try:

    del d:\folders-you-want-to-empty-just-files-from\*.* /s /f /q

    where d: etc is the location of the root folder you want to clear... Think it's v.similar in Swahili!

  5. #5

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    .bat wouls be best please

    i can't get this one to work

    del C:\New Folder\*.* /s /f /q

    Z

  6. #6

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,271
    Blog Entries
    2
    Thank Post
    595
    Thanked 877 Times in 615 Posts
    Rep Power
    277
    Try enclosing the path with quotes - spaces confuses CMD.exe.

  7. #7

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    Ok thanks i will give that ago tomorrow.

    Z

  8. #8

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    Hi

    the command that tonyd posted will only delete files, i need it to delete folders as well.

    Thnaks for your help

    Z

  9. #9

    Gatt's Avatar
    Join Date
    Jan 2006
    Location
    Rochdale
    Posts
    5,293
    Thank Post
    647
    Thanked 368 Times in 259 Posts
    Rep Power
    223
    Quote Originally Posted by FN-Greatermanchester View Post
    Please can somone isnstruct me on a script that will empty the contents of a folder but not the folders itself.

    Cheers
    Quote Originally Posted by FN-Greatermanchester View Post
    Hi

    the command that tonyd posted will only delete files, i need it to delete folders as well.

    Thnaks for your help

    Z

    Sorry Z, but I'm confused - you OP states you only want to delete the files, which means tonyd's Command works.. (deletes all files but no folders)

    But then you say you want to delete the folders too?

    If you want to delete all subfolders, but not the root try this:
    Code:
    @echo off
    pushd %1
    del /q *.* 
    for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
    popd
    taken from here

  10. #10

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    Still haven't got round to doing this

    "Sorry Z, but I'm confused - you OP states you only want to delete the files, which means tonyd's Command works.. (deletes all files but no folders)"

    In my post it says delete the contents of a folder but not the folder itself, sorry for the confusion.

  11. #11
    bizzel's Avatar
    Join Date
    Jul 2007
    Location
    Cambridge
    Posts
    654
    Thank Post
    102
    Thanked 203 Times in 72 Posts
    Rep Power
    46
    Here you go. Something to remove all files and subfolders from a given folder. Just give it the path as "X:\whatever\foo\bar" and away you go. It was done in 5 minutes flat so it's not my finest code. It's quite safe though, it won't go and trash your folders. Promise. See if it does the trick.

    http://www.paulbeesley.com/wp-content/uploads/quickclear.zip

  12. Thanks to bizzel from:

    FN-GM (13th March 2008)

  13. #12

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    thanks but i get Error 404 - Not Found.

    Z

  14. #13
    bizzel's Avatar
    Join Date
    Jul 2007
    Location
    Cambridge
    Posts
    654
    Thank Post
    102
    Thanked 203 Times in 72 Posts
    Rep Power
    46
    Just uploaded it now. Needs .Net 2.0 to be installed btw. You'll probably have it already.

  15. Thanks to bizzel from:

    FN-GM (13th March 2008)

  16. #14

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    Brisbane, Australia
    Posts
    11,181
    Blog Entries
    3
    Thank Post
    537
    Thanked 924 Times in 835 Posts
    Rep Power
    196
    Thanks alot mate, will take a look at that tomorrow.

    Z

SHARE:
+ Post New Thread

Similar Threads

  1. My Documents Empty
    By luketheduck in forum Windows
    Replies: 12
    Last Post: 5th December 2007, 04:16 PM
  2. Replies: 4
    Last Post: 22nd January 2007, 08:48 PM
  3. Replies: 1
    Last Post: 21st January 2007, 03:51 PM
  4. VB Script ti check for folder and then copy contents to PC
    By tosca925 in forum How do you do....it?
    Replies: 4
    Last Post: 2nd October 2006, 08:15 PM
  5. Replies: 2
    Last Post: 1st October 2005, 02:55 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •