+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Scripting to Delete multiple files and folders. in Coding and Web Development; Hello all. I'm trying to create a script to delete multiple files and folders (both empty and full) from numerous ...
  1. #1

    Join Date
    Dec 2010
    Location
    Newcastle
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Scripting to Delete multiple files and folders.

    Hello all.
    I'm trying to create a script to delete multiple files and folders (both empty and full) from numerous folders.
    For example, the students will log on as EPupil01 for an exam.
    They will then create work and save it to \\server\share\path.
    However, I need to be able to copy over this work into another folder, then delete it once the copying is complete.
    I have already completed a batch file that will copy the files, but I can't seem to find any scripts that will delete all files and folders, without deleting the directory itself.

    Any help would be much appreciated.
    Thanks!
    Mark.

  2. #2

    Join Date
    Dec 2010
    Location
    Newcastle
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi there.
    I have been informed by my line manager not to use any sort of software, as it defeats the purpose of the task set.
    Is there any other information anyone could give me, or could anyone point me in the right direction?
    Thanks again,
    Mark.

  3. #3

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,808
    Thank Post
    272
    Thanked 1,135 Times in 1,031 Posts
    Rep Power
    349
    Quote Originally Posted by mdixon123 View Post
    Hi there.
    I have been informed by my line manager not to use any sort of software, as it defeats the purpose of the task set.
    Is there any other information anyone could give me, or could anyone point me in the right direction?
    Thanks again,
    Mark.
    everything is a program - xcopy is a program it just comes with windows

    T

  4. #4

    Join Date
    Dec 2010
    Location
    Newcastle
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Okay then I will re-phrase.
    I am not allowed to use any 3rd party software, I can only use VBScripts, MS-DOS scripts and BAT files etc etc.
    Again, any help would be appreciated.
    Mark.

  5. #5

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,808
    Thank Post
    272
    Thanked 1,135 Times in 1,031 Posts
    Rep Power
    349
    Quote Originally Posted by mdixon123 View Post
    Okay then I will re-phrase.
    I am not allowed to use any 3rd party software, I can only use VBScripts, MS-DOS scripts and BAT files etc etc.
    Again, any help would be appreciated.
    Mark.
    sorry i meant to write the robocopy was a windows program at the end just thought about it!

    robocopy can be used in batch files

  6. #6

    Join Date
    Dec 2010
    Location
    Newcastle
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Ah right excellent. I've created my file anyways, I managed to poke some knowledge from colleagues and websites, however, I still need to be able to pipe in information from an excel spreadsheet.
    For example, I need to be abe to delete all files and folders from 88 accounts' N:\ drives. So I will need something like this:

    [COMMAND] \\ser-ver-001\Pupil01$
    [COMMAND] \\ser-ver-001\Pupil02$

    etc etc until I get to Pupil88.

    Could someone please shed some light on this?
    Thank You.
    Mark.

  7. #7


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,900
    Thank Post
    226
    Thanked 2,676 Times in 1,973 Posts
    Rep Power
    787
    Quote Originally Posted by jinnantonnix View Post
    Robocopy is part of Windows as of XP SP3.
    Not quite true. It's only bundled with Windows Vista and 7 (and Windows Server 2008/2008 R2).

  8. #8

    Join Date
    Apr 2008
    Location
    Keighley, West Yorks
    Posts
    326
    Thank Post
    52
    Thanked 49 Times in 43 Posts
    Rep Power
    21
    Quote Originally Posted by mdixon123 View Post
    I've created my file anyways, however, I still need to be able to pipe in information from an excel spreadsheet.
    I will need something like this:

    [COMMAND] \\ser-ver-001\Pupil01$
    [COMMAND] \\ser-ver-001\Pupil02$

    etc etc until I get to Pupil88.
    Mark,

    If you're using batch scripts, i'm pretty sure you would need the 'for' command, but I don't know it enough to tell you the correct synax - I always have to look it up and copy/paste examples from other sites.

    It basically says (for every line in the csv file, do the following: [COMMAND] \\ser-ver-001\<CSV_LINE>).

    Or, you could use excel to generate the whole batch file for you - this is my preferred solution.

    So if column A contains a list of \\ser-ver\Pupil01$, \\ser-ver\Pupil02$ etc, in cell B1 you would write a formulae =concatenate("[COMMAND] ",a1) and copy it down (which would then change a1 to a2, a3, a4...) - then copy the whole column B to a text document and save as a batch file, then execute (or have a macro button do it for you).

    Peter

  9. #9
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    Can't remember where I got this, and I modifed it slightly by commenting some bits out as we use it to clear a temp folder, but I think this the type of thing that you are looking for:

    Code:
    Set fso=CreateObject("Scripting.FileSystemObject")
    CleanPath="E:\Network Temp\"
    
    For Each file In fso.GetFolder(CleanPath).Files
    file.attributes = file.attributes And Not 1
    file.delete
    Next
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder("E:\Network Temp\")
    
    arrFolders = Array()
    For Each oFolder In oFolder.SubFolders
    ' Note : Only use *lowercase* letters in the folder names below:
    'If Not LCase(oFolder.Name) = "foldera" _
    'And Not LCase(oFolder.Name) = "folderb" _
    'And Not LCase(oFolder.Name) = "folderc" Then
    intCount = UBound(arrFolders) + 1
    ReDim Preserve arrFolders(intCount)
    arrFolders(intCount) = oFolder.Path
    'End If
    Next
    
    For n = 0 To UBound(arrFolders)
    fso.DeleteFolder arrFolders(n), True
    Next
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("E:\Network Temp\The contents of this drive will be deleted every night")
    Out of interest why aren't you allowed to use a program to acheive this? Technically the script interpreter is a program you just don't see any evidence of it running unless you get an error.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 6
    Last Post: 12th September 2011, 10:24 AM
  2. Unshare/delete multiple home folders
    By DreCon in forum Windows
    Replies: 2
    Last Post: 5th October 2010, 03:04 PM
  3. Replies: 5
    Last Post: 9th March 2008, 12:15 AM
  4. Delete a folder using scripting
    By FN-GM in forum Scripts
    Replies: 15
    Last Post: 22nd December 2007, 04:44 PM
  5. Replies: 15
    Last Post: 19th September 2007, 10: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
  •