mdixon123 Posted December 16, 2010 Report Posted December 16, 2010 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.
mdixon123 Posted December 17, 2010 Author Report Posted December 17, 2010 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.
glennda Posted December 17, 2010 Report Posted December 17, 2010 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
mdixon123 Posted December 17, 2010 Author Report Posted December 17, 2010 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.
glennda Posted December 17, 2010 Report Posted December 17, 2010 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
mdixon123 Posted December 17, 2010 Author Report Posted December 17, 2010 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.
Arthur Posted December 17, 2010 Report Posted December 17, 2010 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).
howartp Posted December 23, 2010 Report Posted December 23, 2010 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
morganw Posted January 2, 2011 Report Posted January 2, 2011 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now