Solved

Looking for a vb script for searching for about 200 folders in a volume and deleting it's content

Posted on 2013-01-14
13
150 Views
Last Modified: 2013-01-23
I'm looking for a script for cleaning a temp folder in about 200 joomla site on a WEB server
0
Comment
Question by:Provost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 78

Expert Comment

by:arnold
ID: 38775685
There are many examples of vbscripts and the fileobject using which you can iterate through subdirectories in search of files meeting your criteria.
0
 

Author Comment

by:Provost
ID: 38775840
If you found a solution who is filled my requirement, could you send the link?
0
 
LVL 78

Expert Comment

by:arnold
ID: 38775956
Here is a basic reference to a vbscript that drills down through the directory structure.
http://stackoverflow.com/questions/1433785/vbscript-to-iterate-through-set-level-of-subfolders

You can build of this to expand.

Are you sure you should not be going through the Joomla database and deleting entries/references/directories based on the data within the database.
Doing it on the file system level, could result in orphan records in the database.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 20

Expert Comment

by:ltlbearand3
ID: 38781144
If I understand this right you want to remove the temp folder and all items in the folder including sub folders?  Correct?  If so, there is a slightly simpler method than the one linked above.  Just use the DeleteFolder method.  See the sample code below, make sure the path is correct (strRemoveFolder)

Dim strRemoveFolder, objFSO

' Set the Path to the Folder Here
strRemoveFolder = "c:\YourFolderPathHere\TempOrWhatever"

' Instantiate the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Verify the Folder Exists
If objFSO.FolderExists(strRemoveFolder) then
        ' Force Deletion of the folder
	objFSO.DeleteFolder strRemoveFolder, True
End IF

' Clean up
Set objFSO = nothing

' Let the user know we are done.
msgbox "Done"

Open in new window


-Bear
0
 

Author Comment

by:Provost
ID: 38781301
Hi Bear,

Sorry but it is not that simple. We want a script who is going to search for a folder named Temp. There is about 200 folders with that name in my WEB volume ( one folder per joomla installation) I want to find them, delete the content but not the folder.

Do you have a solution for that?

Thank you
0
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 38781345
We would need a combination of the two solutions.  I am not familiar with the joomla folder structure.  Can we just look for a folder named "temp" in a certain folder tree?  If so, try something like this setting strFolderToSearch to the parent folder the search.

Dim strFolderToSearch, objFSO, objMainFolder, objFolder

' Set the Path to the Folder Here
strFolderToSearch = "c:\YourFolderPathHere\TempOrWhatever"

' Instantiate the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Get Access to the Parent Folder
Set objMainFolder = objFSO.GetFolder(strFolderToSearch)

For each objFolder in objMainFolder.SubFolders
	' Check if we found the temp folder
	If objFolder.Name = "Temp" Then
		' We did.  Force Delete
		objFolder.Delete(True)
	Else
		' Not the temp folder, keep looking
		SearchSubFolders objFolder
	End IF
Next

' Clean up
Set objFolder = Nothing
Set objMainFolder = Nothing
Set objFSO = nothing

' Let the user know we are done.
msgbox "Done"

Sub SearchSubFolders (FolderToSearch)
	Dim objSubFolder

	For each objSubFolder in FolderToSearch.SubFolders
		' Check if we found the temp folder
		If objSubFolder.Name = "Temp" Then
			' We did.  Force Delete
			objSubFolder.Delete(True)
		Else
			' Not the temp folder, keep looking
			SearchSubFolders objSubFolder
		End IF
	Next
End Sub

Open in new window


-Bear
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 38799462
Here's a simple BAT file that will do the job:

@echo off
for /d /r "c:\joomla" %D in (temp.*) do (
  if "%%~xD" == "" rd /s /q "%%~D"
)

Open in new window

~bp
0
 

Author Comment

by:Provost
ID: 38801660
Hi Bill,

Thank you for the solution you  sent. When i tried to execute the batch file, i got the error
"D was expected"

Am i doing something wrong?

I'm running Windows 7 64 bits french
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 38803534
Sorry, small typo, try this:

@echo off
for /d /r "c:\joomla" %%D in (temp.*) do (
  if "%%~xD" == "" rd /s /q "%%~D"
)

Open in new window

~bp
0
 

Author Comment

by:Provost
ID: 38803729
Hi Bill,

You are close, i don't want to delete the temp folder just it's content.
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 38803745
Okay, didn't understand that, this should take care of that.

@echo off
for /d /r "c:\joomla" %%D in (temp.*) do (
  pushd "%%~D"
  if "%%~xD" == "" rd /s /q "%%~D" >NUL 2>&1
  popd
)

Open in new window

~bp
0
 

Author Closing Comment

by:Provost
ID: 38811062
Thank you for the effort!
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 38811282
Welcome.

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question