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
146 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 52

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 52

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 52

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 52

Expert Comment

by:Bill Prew
ID: 38811282
Welcome.

~bp
0

Featured Post

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pass through dll 2 66
Domino Website - Redirection 12 54
VBscript/Batch file: copy files/folders based on a csv file 15 65
Batch/VBScript : Disable Windows tasks 7 25
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

863 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

25 Experts available now in Live!

Get 1:1 Help Now