+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
Scripts Thread, Delete a folder using scripting in Coding and Web Development; How do I delete a folder using a script, how easy is it please as i am not a script ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,249
    Thank Post
    898
    Thanked 1,785 Times in 1,537 Posts
    Blog Entries
    12
    Rep Power
    463

    Delete a folder using scripting

    How do I delete a folder using a script, how easy is it please as i am not a script expert.

    Thanks

    Z

  2. #2

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,924
    Thank Post
    3,456
    Thanked 1,089 Times in 1,004 Posts
    Rep Power
    371

    Re: Delete a folder using scripting


  3. #3

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,069 Times in 625 Posts
    Rep Power
    740

    Re: Delete a folder using scripting

    Type in on a command line DEL /? and RMDIR /?
    Or AutoITs DirRemove.

    Code:
    ; Delete C:\Test1 and all subdirs and files
    DirRemove("C:\Test1", 1)

  4. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,249
    Thank Post
    898
    Thanked 1,785 Times in 1,537 Posts
    Blog Entries
    12
    Rep Power
    463

    Re: Delete a folder using scripting

    Hi

    I am trying to remove things from the start menu that are not need.

    @mattx thanks for that, is that a VBS or BAT script please?

    Thanks

  5. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,924
    Thank Post
    3,456
    Thanked 1,089 Times in 1,004 Posts
    Rep Power
    371

    Re: Delete a folder using scripting

    The script is an auto it script , the commands he posted before that are from command line.

    Depends what you want to do, I mean you could put the command line commands into a bat file.

  6. #6

    Join Date
    Sep 2007
    Location
    United Kingdom
    Posts
    5
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Delete a folder using scripting

    Code:
    //JScript
    var fso;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.DeleteFolder("C:\\foldername");
      
    'VBScript
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.DeleteFolder("C:\\foldername")
    Code from JScript5.chm and Vbscrip5.chm

    Edit: Sorry guys, vbscript uses one slash and JScript uses two slashes. JScript uses two slashes as the first slash is used to denote an escaped character such as \n \r \t etc where as vbscript use vbCr vbLf vbTab and so on.

  7. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,924
    Thank Post
    3,456
    Thanked 1,089 Times in 1,004 Posts
    Rep Power
    371

    Re: Delete a folder using scripting

    Quote Originally Posted by arran
    Code:
    //JScript
    var fso;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.DeleteFolder("C:\\foldername");
      
    'VBScript
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.DeleteFolder("C:\\foldername")
    Code from JScript5.chm and Vbscrip5.chm
    Bit of a daft question but I have always seem some code snippets in delete or copy files or folders with one slash ie \ and others with 2 ie \\

    such as this :

    [quote="arran"][code]//JScript
    var fso;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.DeleteFolder("C:\\foldername");

    'VBScript
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.DeleteFolder("C:\\foldername") '<-- in the directory path there is \\

    Just wanted to know what difference does it make ?

  8. #8


    Join Date
    Jul 2007
    Location
    Rural heck
    Posts
    2,662
    Thank Post
    120
    Thanked 433 Times in 352 Posts
    Rep Power
    126

    Re: Delete a folder using scripting

    There's a freeware prog called orphan remover that scans the start menu for dead shortcuts and removes them. It can be ran in a quiet mode from a script.

    Where I used to work for had student accounts set up not to process the all users profile instead all the shortcuts came from the students mandatory profile. We then had orphan remove set to kill the shortcuts for any progs that weren't installed on that particular machine.

  9. #9
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Delete a folder using scripting

    Have a look on the microsoft scripting site. There a plenty of snippets on there you can play around with and put together to make your own scripts. If you look under the sticky in the scripting section you will also see a few programs that will create basic scripts for you.

  10. #10

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,249
    Thank Post
    898
    Thanked 1,785 Times in 1,537 Posts
    Blog Entries
    12
    Rep Power
    463

    Re: Delete a folder using scripting

    Thanks guys i ended up using this

    'VBScript
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.DeleteFolder("C:\\foldername")
    Z

  11. #11

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,249
    Thank Post
    898
    Thanked 1,785 Times in 1,537 Posts
    Blog Entries
    12
    Rep Power
    463

    Re: Delete a folder using scripting

    Using this code

    'VBScript
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.DeleteFolder("C:\\Documents and Settings\All Users\Start Menu\Programs\folder1")
    fso.DeleteFolder("C:\\Documents and Settings\All Users\Start Menu\Programs\folder t2")
    When the folder does not exist i get the following message, any ideas please?
    Last edited by FN-GM; 25th June 2008 at 03:47 PM.

  12. #12

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,071
    Thank Post
    210
    Thanked 430 Times in 310 Posts
    Rep Power
    144

    Re: Delete a folder using scripting

    stick
    Code:
     On Error Resume Next
    at the start of your script, that will ignore any errors thay occur when it runs.

    Mike.

  13. #13
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Delete a folder using scripting

    Quote Originally Posted by maniac
    stick
    Code:
     On Error Resume Next
    at the start of your script, that will ignore any errors thay occur when it runs.

    Mike.
    Thats the easy way but the correct way would be to check if the folder exists then try and delete it else do nothing.

  14. #14

    Join Date
    Mar 2006
    Posts
    537
    Thank Post
    2
    Thanked 3 Times in 2 Posts
    Rep Power
    19

    Re: Delete a folder using scripting

    I suspect that the problem is with the double back slash in the VBS.
    I don't recall having to use it in leteral path references.

    Now JScript with its nod to its Java/Unix roots uses // because a single forward slash in a quoted string normally introduces control characters.

  15. #15

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,071
    Thank Post
    210
    Thanked 430 Times in 310 Posts
    Rep Power
    144

    Re: Delete a folder using scripting

    Quote Originally Posted by ChrisH
    Quote Originally Posted by maniac
    stick
    Code:
     On Error Resume Next
    at the start of your script, that will ignore any errors thay occur when it runs.

    Mike.
    Thats the easy way but the correct way would be to check if the folder exists then try and delete it else do nothing.
    You are indeed correct! (but I'm always one for the easy option.)

    My VBS coding skills are limited!

    Mike.



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 8
    Last Post: 17th November 2007, 10:04 PM
  2. delete same folder from all users home area
    By markcuk in forum How do you do....it?
    Replies: 27
    Last Post: 25th April 2007, 11:38 AM
  3. Got a folder I cannot delete or take ownership of
    By sidewinder in forum Windows
    Replies: 2
    Last Post: 20th March 2007, 03:49 PM
  4. Replies: 1
    Last Post: 21st January 2007, 03:51 PM
  5. Replies: 3
    Last Post: 25th September 2006, 01:27 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
  •