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
145 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 76

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 76

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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 51

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 51

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 51

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 51

Expert Comment

by:Bill Prew
ID: 38811282
Welcome.

~bp
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now