+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Script to delete specific folders in Coding and Web Development; Hi, I am new to scripting! Please excuse me if I display any dumbness over the post! I am interning ...
  1. #1

    Join Date
    Jun 2008
    Location
    USA
    Posts
    2
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Unhappy Script to delete specific folders

    Hi,

    I am new to scripting! Please excuse me if I display any dumbness over the post!

    I am interning in a company now and I have a problem. A large number of Home shares for users were retained by the company due to legal reasons. Now they 've decided to get rid of home drives that belonged to certain users... about 2000 of them. These hidden folders are over different remote servers. I can prepare an excel or txt with the paths of all these folders. I need a script that can pick these paths one-by-one and delete entire folders along with sub-folders.

    I have a super-admin account so access wont be an issue.

    Please help!!!!!!

  2. #2
    superfletch's Avatar
    Join Date
    Nov 2007
    Location
    South
    Posts
    445
    Thank Post
    153
    Thanked 77 Times in 61 Posts
    Rep Power
    32

    Remove directorie with batch file:

    The command for this should be something like this (as long as you are working from the machine your directories reside on) if Iím not mistaken:

    cd..

    cd..

    RMDIR X:\YOURPATHNAME\HOMEFOLDER$ /s /q

    /s being to remove all subdirectories
    /q being to do it without confirmation

    Note that you cannot be inside the directory that you are deleting; else you will be prompted with the message "The process cant access the folder because it is being used by another process".

    If your text file is prepared as follows (and the majority of your home folders reside in one or two locations then you could do the following:

    Imagine this is a few lines of your text file:

    X:\Users\Home Folders\USERNAME1$
    X:\Users\Home Folders\USERNAME2$
    X:\Users\Home Folders\USERNAME3$
    X:\Users\Home Folders\USERNAME4$

    Use the edit menu and choose to replace:

    In the find box enter:

    X:\Users\Home Folders\

    In the replace box enter:

    RMDIR X:\Users\Home Folders\

    Then choose replace all:

    Repeat this for any other locations you might have then concentrate on adding the switches Ė again by using find and replace.

    In the find box choose to find a $ sign and choose to replace it with $ /s /q

    (Obviously your directories need to end in $ signs)Ö

    Now save the text file as a .bat file.

    The script should then do the rest when you run it. Needless to say be sure you are targeting the right folders, Iím sure someone here will point out if Iíve made any mistakes with this..

  3. Thanks to superfletch from:

    Baasha_Bhai (5th June 2008)

  4. #3

    Join Date
    Jun 2008
    Location
    USA
    Posts
    2
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thank You for your timely suggestions guys. Let me work on it and get back to you!

  5. #4

    Join Date
    Jun 2008
    Location
    Asheville
    Posts
    6
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Don't forget the quotes

    The suggestions look good to me, but I always
    forget to put quotes around the directory names
    and some of the names have spaces in them.

    Do this:
    rd "Folder To Remove"

    Instead of:
    rd Folder To Remove

    Mike Honeycutt
    UNC Asheville

  6. #5

    Join Date
    Jun 2008
    Location
    Asheville
    Posts
    6
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Cool

    Thanks for teaching an old dog a new trick - I've never heard of this feature.

    Now that I'm an "expert", I might suggest:

    1. CMD prompt
    2. EDIT killfile.txt in case mistakes occur that need to be fixed.

    Thanks again for the tip

    Mike Honeycutt

  7. #6
    superfletch's Avatar
    Join Date
    Nov 2007
    Location
    South
    Posts
    445
    Thank Post
    153
    Thanked 77 Times in 61 Posts
    Rep Power
    32
    Thats Awesome.

  8. #7
    Hacksawbob's Avatar
    Join Date
    Apr 2008
    Location
    North West UK
    Posts
    192
    Thank Post
    13
    Thanked 20 Times in 16 Posts
    Blog Entries
    2
    Rep Power
    18
    thanks for that, I'm sure I'll need it one day!

  9. #8
    superfletch's Avatar
    Join Date
    Nov 2007
    Location
    South
    Posts
    445
    Thank Post
    153
    Thanked 77 Times in 61 Posts
    Rep Power
    32
    Quote Originally Posted by jinnantonnix View Post
    It's also useful if you've got a command-line window open and you want to change directory to something like "c:\my stuff\this directory name is so long i dont think i could type it in again without making a mistake".
    You could just start writing the folder name and use tab!!

    Sorry couldn't help it.

  10. #9

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,247
    Thank Post
    1,059
    Thanked 1,069 Times in 625 Posts
    Rep Power
    740
    Some may find this handy....
    You will need to compile it first - [ I did it in AutoIT ]
    When run it will delete all the files & folders in the directory apart from the folder 'keep me'
    I run this every year on our students home directories.

    Code:
    $search = FileFindFirstFile("*.*")
    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf
    
    While 1
        $file = FileFindNextFile($search)
        If @error <> 0 Then ExitLoop
        If $file = "keep me" Then ContinueLoop
        If $file = "." Or $file = ".." Then ContinueLoop
        If StringInStr(FileGetAttrib(@SCRIPTDIR & "\" & $file) , "D") Then
            DirRemove($file, 1)
        Else
            FileDelete(@SCRIPTDIR & "\" & $file)
        EndIf
    WEnd
    FileClose($search)
    If you want a compiled version - just ask and I'll copy it up...



SHARE:
+ Post New Thread

Similar Threads

  1. VB script to delete certain folders
    By PTD in forum Scripts
    Replies: 7
    Last Post: 4th June 2008, 01:30 PM
  2. Script to delete certain folders
    By Pumaedition in forum Scripts
    Replies: 4
    Last Post: 22nd April 2008, 11:08 PM
  3. Replies: 2
    Last Post: 17th April 2008, 12:25 PM
  4. Replies: 5
    Last Post: 9th March 2008, 01:15 AM
  5. Replies: 15
    Last Post: 19th September 2007, 11:46 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
  •