Jump to content

Scripting to Delete multiple files and folders.


Recommended Posts

Posted

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. :cool:

Posted

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.

Posted
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

Posted

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.

Posted
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

Posted

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.

Posted
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\).

 

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

  • 2 weeks later...
Posted

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:

 

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...