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
148 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

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.

Question has a verified solution.

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

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

777 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