+ 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
    UK
    Posts
    16,311
    Thank Post
    901
    Thanked 1,797 Times in 1,548 Posts
    Blog Entries
    12
    Rep Power
    466

    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,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    What language?

  3. #3

    Dos_Box's Avatar
    Join Date
    Jun 2005
    Location
    Preston, Lancashire
    Posts
    9,342
    Thank Post
    676
    Thanked 2,271 Times in 1,047 Posts
    Blog Entries
    23
    Rep Power
    673
    Ooh! Choice. Swahili please

  4. #4
    tonyd's Avatar
    Join Date
    Mar 2006
    Location
    Kent (Sometimes), UK
    Posts
    163
    Thank Post
    17
    Thanked 42 Times in 31 Posts
    Rep Power
    25
    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
    UK
    Posts
    16,311
    Thank Post
    901
    Thanked 1,797 Times in 1,548 Posts
    Blog Entries
    12
    Rep Power
    466
    .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,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    Try enclosing the path with quotes - spaces confuses CMD.exe.

  7. #7

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,311
    Thank Post
    901
    Thanked 1,797 Times in 1,548 Posts
    Blog Entries
    12
    Rep Power
    466
    Ok thanks i will give that ago tomorrow.

    Z

  8. #8

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,311
    Thank Post
    901
    Thanked 1,797 Times in 1,548 Posts
    Blog Entries
    12
    Rep Power
    466
    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
    Posts
    6,806
    Thank Post
    880
    Thanked 684 Times in 453 Posts
    Rep Power
    505
    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
    UK
    Posts
    16,311
    Thank Post
    901
    Thanked 1,797 Times in 1,548 Posts
    Blog Entries
    12
    Rep Power
    466
    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 204 Times in 72 Posts
    Rep Power
    51
    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
    UK
    Posts
    16,311
    Thank Post
    901
    Thanked 1,797 Times in 1,548 Posts
    Blog Entries
    12
    Rep Power
    466
    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 204 Times in 72 Posts
    Rep Power
    51
    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
    UK
    Posts
    16,311
    Thank Post
    901
    Thanked 1,797 Times in 1,548 Posts
    Blog Entries
    12
    Rep Power
    466
    Thanks alot mate, will take a look at that tomorrow.

    Z



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 5
    Last Post: 29th January 2013, 11:16 AM
  2. My Documents Empty
    By luketheduck in forum Windows
    Replies: 12
    Last Post: 5th December 2007, 04:16 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, 09:15 PM
  5. Replies: 2
    Last Post: 1st October 2005, 03: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
  •