VBS Removing files within a directory using FileSystemObject with exceptions? - oracle

I work with the rather finnicky Oracle Business Intelligence software and we often have issues that entail, clearing out specific data on users systems, and then synchronizing with the server to pull down the data again. I've got a vbs script that I'm working on that removes key directories, and renames others and stops services etc.
Where I'm stuck is on one specific directory. Using FileSystemObject, what would be the easiest way to remove every single file within a directory with the exception of a single folder?
So, for this specific example, I have C:\OracleBIData\sync\config
Where I want to delete everything inside of the "sync" directory, with the exception of the config directory. Any takers?

Snippet:
Option explicit
Const folderspec = "C:\OracleBIData\sync"
Const excludeFolder = "C:\OracleBIData\sync\config"
deleteSubFolders CreateObject("Scripting.FileSystemObject").GetFolder(folderspec), excludeFolder
Public Sub deleteSubFolders(byRef MyFolder, exclFolder)
Dim sf
For Each sf in MyFolder.SubFolders
If not (lCase(sf.Path) = lCase(exclFolder)) Then
deleteSubFolders sf, exclFolder
sf.Delete
End If
Next
End Sub
It will not delete folders under the excludeFolder.

Brute force is all I can think of.
Walk through the directory item but item and delete it if it is not config. Or if this directory has lots and lots and lots of files, first run through deleting a*., b.*, d*.* 25 times, and then walk through the rest of the items.

Related

UFT OTA - Get ID of copied test set folder

I have (after FOREVER) figured out how to copy a test set folder from one location to another and rename it using a explicit folder id. Now, I want to rename the new folder right after pasting, so the id will NOT be known. I have found absolutely NOTHING on how I can do this.
I'm trying my hardest to use the online resource for OTA, but it's really unhelpful unless you already know the language. I can't seem to find what I need, so please don't suggest that.
Thanks in advance. Currently very frustrated and ready to throw out my computer.
Here's what I have to copy, paste, and rename a specific node by id
Set qcConnection = QCutil.QCConnection
copiedTestSet = qcConnection.TestSetTreeManager.CopyToClipboard(3)
QCConnection.TestSetFactory.PasteFromClipboard copiedTestSet,6,2,1
Set renameTest = qcconnection.TestSetTreeManager.NodeByID(30)
print renameTest.Name
renameTest.Name = "Rename Test"
renameTest.Post
Set renameTest = Nothing
Set copiedTestSet = Nothing
You will know the folder name of the pasted folder, because it should be same as the copied folder, you can simple search for the pasted folder with name under the parent folder.
Below page have few functions which can help you
https://github.com/sumeet-kushwah/ALM_OTA_Wrapper/blob/master/ALM_Wrapper/TestLabFolders.cs
There are three functions you should search for
FindChildFolderByName
FindChildFolders
GetTestSetFolder
I was able to find what I needed using sumeet's suggestion above. My exact code is below using variables because I need to be able to run this with any folder. It runs right after the paste command above. I had to insert a wait after pasting for some reason, but it works for now. I'll trouble shoot that later
Set renameTest = qcconnection.TestSetTreeManager.NodeByPath(strPath & "\" & strEventFolder)

How to do a function for every folder containing certain file?

I'm having a bit of trouble with AppleScript...
Long story short - what I'm trying to do is to do a function for every folder of parrentFolder containing someFile.
Basicaly, I have a complex folder structure with multiple folders ending up with a couple of files, within which (sometimes) there's a 'Preview.png' file. Now what I'm trying to do is to run a function that will go over each and every folder and whenever it finds 'Preview.png' within a folder it should store folder's path after which I can run a function to change the icon of that folder to a 'Preview.png' image. And it should loop over all of the folders in the main folder.
Anyone able to give me a hand?
Thanks,
Marko

efficient directory traversal for archivable folders

There is a file server I have been asked to clean up (Pentium 4! with 512 meg of ram!!). It gets files added to a directory structure that consists of a few provinces, within each province directory are town directories, within each town directory are are 'newspaper' directories, within each newspaper directory are 'story' directories, and within each story directory are are files named by a string consisting of topic and date. So each file looks like this:
water poisons yak 2013-04-11.doc, malaria peak 2012-01-05, etc. I have to filter this collection for story directories that are inactive (no contributions within 3 years). The collection is to be filtered once a month. About 1000 new files get added every month. The collection has 80,000 files.
My solution is to run through each story directory and check the name of each file with this:
Sub LoopThroughFiles(storyfolder)
Dim MyObj As Object, MySource As Object, file As Variant
file = Dir(storyfolder)
While (file <> "")
If (InStr(file, "2013") Or InStr(file, "2014") > 0) Then
MsgBox "recent file found. move on to next directory"
recentDir = True
Exit Sub
End If
file = Dir
Wend
End Sub
This checks if the year 2013 or 2014 are in the filename. If those years are not found,then I run through the story folder again checking for the year 2012 and the month in a similar way. If a month more recent than the current one is not found, then that whole story directory is moved. In Visual Basic, this is accomplished by changing the pathname of every file in that particular story directory. So this means I run through the story folder Again (a third time), this time assigning a different pathname to each file.
My question has to do with the correct design of this algorithm to be efficient. To know if a folder can be archived, the filenames of its contents have to be inspected.
If I loop through the whole collection in the beginning and load it into an array (to make the subsequent searches faster ) then I will need a ton of memory. On the other hand, looping through each directory three times seems wasteful. I feel like this question should have been solved already so I ask.
Although I have to use visual basic, the principles behind this question are fundamental and applicable to any language. Do not hesitate to reply in another computer language (in English though).

get subfolders without For Each Loop?

Is there any method in vb6 to get the Subfolder name without using For Each Loop?
Most of thread suggests using For Each with FSO, but what if I want to get the subfolder name of specific Folder? e.g. Folder next to C:\Windows ?
I badly need this method to minimize the process time in my program. Simply escaping the loop isn't enough for me.
If you're asking what I think you are (how to list the subfolders of C:\Windows), the answer is no, not without looping.
The reason is that internally the VB FSO uses FindFirstFile, along with the accompanying FindNextFile and FindClose you'll find linked on that page) to iterate the subfolders of a specified folder. The loop is necessary once FindFirstFile has found the first match in order to call FindNextFile to continue retrieving the folders, and FindClose once the last match has been found and the next iteration fails.

Copy Update Create VBScript

Please help me to acheive the following using VBScript
1.Messagebox with three tabs Copy,Update,Cancel and displaying "Welcome to the AVG
definition fies copier/updater module.Click on Copy to copy files or Update to update
definition files.
2.If copy selected,the drive letter from where the script is run(usb drive) stored as
variable,directory "(usb drive)Update" created if not exist,new and files not existing
in update folder copied to(eg=xcopy /d), from
"%allusersprofile%\applic~1\avg8\update\download"
3.If possible display message 'copying files, while copying.After completion of
copying display 'Files copied successfully'.
4.If update selected,tdirectory "c:\Update" created if not exist,new and files not
existing in "c:\Update" copied to, from (usb drive) update folder
5.If possible display message 'Updating files' while copying.After completion of
updating, display 'Files Updated successfully'.After clicking OK exit and start
"C:\progra~1\avg\avg8\avgui.exe"
Well, the way that I would do it is to make stand alone functions for each of the functional tasks that you have then wrap those functions inside an HTA to give you the interface layer that you want.
As I understand from your other question, you managed to find solutions to most of these tasks yourself. Here's a tip for your #2, which I haven't noticed implemented in that your script.
2.If copy selected,the drive letter from where the script is run(usb drive) stored as variable
You can retrieve the full path of the current script file using the WScript.ScriptFullName property and then use the FileSystemObject.GetDriveName method to extract the drive letter:
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUSBDrive = objFSO.GetDriveName(WScript.ScriptFullName)
This will give you the drive letter followed by a colon (e.g. J:). You can then concatenate this value with the target folder name to get the full path, e.g.:
MsgBox strUSBDrive & "\Update"

Resources