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
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
149 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
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 77

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 77

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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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 53

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 53

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 53

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 53

Expert Comment

by:Bill Prew
ID: 38811282
Welcome.

~bp
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

860 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