I have this below vbscript to get one of the details of a file (we get by View->Choose Details in active folder window) which will retrieve Title detail/property of that file.
folder = "D:\StrongBox\Desktop\CSS The Complete Guide\01 Getting Started"
filename = "001 Introduction.mp4"
Set ShellObj = CreateObject("Shell.Application")
Set FolderObj = ShellObj.Namespace(folder)
MsgBox FolderObj.GetDetailsOf(FolderObj.Parsename(filename), 21)
How to set the detail of the the file?
I could not find a function like SetDetailsOf.
Related
How do I take the user input and let that be the directory for a text file?
I tried putting quotes around the ("Inp.txt") but this doesn't read the actual user input.
Set oFSO = CreateObject("Scripting.FileSystemObject")
Inp= InputBox("Please Enter Desired Location of Log File:")
If Inp= "" Then
Set oTF = oFSO.CreateTextFile("C:\Old Files.txt")
Else
Set oTF = oFSO.CreateTextFile(Inp.txt)
End If
I want to prompt the user for an input asking where they'd like to place their created text file; if left blank i would set it to a default location. I tried setting an inputbox prompt but when i use that as the text file location I receive an "Object Required" runtime error.
Build a complete path from the directory and a file name:
Set oTF = oFSO.CreateTextFile(oFSO.BuildPath(Inp, "output.txt"))
I would recommend letting the users browse for the folder, though.
Set app = CreateObject( "Shell.Application" )
Set d = app.BrowseForFolder(0, "Select Folder", 1, "C:\")
If d Is Nothing Then
Inp = "C:\"
Else
Inp = d.Self.Path
End If
Set oTF = oFSO.CreateTextFile(oFSO.BuildPath(Inp, "output.txt"))
I'm currently using UFT -- I have a GUI test, and there's a web element object in one of my tests I'd like to delete/update, but I'm worried it's being referenced by another test in our test suite. (I am coming into a test suite that someone else built)
Is there anyway to tell whether or not an object in the object repository is being used in other tests? (Without having to go into each individual test and action to find out?)
My way would be simple recursive file search.
Open EditPlus
Search -> Find In Files
Find What =
File Type = *.mts | *.vbs | *.qfl
Folder =
Select the Include Sub Folder Check Box
Click Find
You can use Search>View>Find (or ctrl+F) from UFT and select to look in entire solution
Open "Script.mts" file from every action and search for your object name. If you find the object, write the script name and line number where your object exists, in a file.
Use the below code:
'strScriptsPath is the path where your test script folders are placed.
Set strScripts = objFSO.GetFolder(strScriptsPath).SubFolders
For Each Script In strScripts
strAction = strScriptsPath & "\" & Script.Name & "\Action1\Script.mts"
If objFSO.FileExists(strAction) Then
'Open Script in NotePad
Set strFile = objFSO.OpenTextFile(strAction, 1)
Do While Not (strFile.AtEndOfStream)
strLine = strFile.ReadLine
If InStr(1, strLine, strObjectName) > 0 Then
iVerificationCount = objSheet.UsedRange.Rows.Count
iCurrentRow = iVerificationCount + 1
objSheet.Cells(iCurrentRow, 1) = Script.Name
objSheet.Cells(iCurrentRow, 2) = strLine
If strFile.AtEndOfStream Then
objSheet.Cells(iCurrentRow, 3) = strFile.Line
Else
objSheet.Cells(iCurrentRow, 3) = strFile.Line - 1
End If
End If
Loop
strFile.Close
Set strFile = Nothing
End If
Next
Set strScripts = Nothing
To be able to use this code, declare objFSO object and write a piece of code to create an excel and get objSheet.
You can also replace the object name using the below code:
Use the For Each Loop as mentioned above
strScript = strScriptsPath & "\" & strScriptName & "\Action1\Script.mts"
strFind = "Old Object Name"
strReplace = "New Object Name"
Set strFile = objFSO.OpenTextFile(strScript, 1)
strData = strFile.ReadAll
strNewData = Replace(strData, strFind, strReplace)
strFile.Close
Set strFile = Nothing
Set strFile = objFSO.OpenTextFile(strScript, 2)
strFile.Write strNewData
strFile.Close
Set strFile = Nothing
** You just need to write this entire code in a .vbs file and run that file.
I am using UFT 12.5. During run time it opens excel and word. Then it writes some data in the both files. After that, I would like to save both files with a new name and then password protected. I need to be able to enter password manually to open it. So far, I have written the below code and I getting an error at the last line.
Set ExcelObj = createobject("excel.application")
ExcelObj.Visible = true
Set ExcelFile = ExcelObj.Workbooks.Open (file)
Set ScripSheet = ExcelFile.Worksheets("Scripts")
ScripSheet.Cells(1,1) = "Passed"
ExcelFile.SaveAs mm1, "ttt"
Please advise on how I can save word and excel files with a password using UFT.
Thanks.
You need to pass correct parameters with SaveAs method. Check this link for more info.
Here is the working code that you can try:
file = "File path with file name"
newfile = "File path with new file name"
Set ExcelObj = createobject("excel.application")
ExcelObj.Visible = true
Set ExcelFile = ExcelObj.Workbooks.Open (file)
Set ScripSheet = ExcelFile.Worksheets("Scripts")
ScripSheet.Cells(1,1) = "Passed"
ExcelFile.SaveAs newfile, , "test"
ExcelFile.Close
ExcelObj.Quit
UPDATE
Per comments from OP
If you want to save file with ReadOnly, you have to use WriteResPassword parameter this way:
ExcelFile.SaveAs newfile, , , "test"
Note that I've two empty parameters for FileFormat and
Password respectively.
This way it will ask for password to open the file in write mode and if you won't provide the password, file will be opened in ReadOnly
mode.
Check the link that I've mentioned.
I'm trying to write a script in VBS to show the file properties dialog/sheet for multiple items. Those items will be all of the items in a parent folder (e.g. all items in W:\).
Essentially, I'm trying to get the properties dialog to show the number of files in a drive. Right-clicking on the drive and selecting Properties does not show the number of files. You would instead need to go into the first level of the drive, select all folders/files, and then right-click and select Properties.
I have customised some code (below) I've found on the internet to bring up the file properties dialog/sheet for either a specific folder, or a drive. I have no idea what I could further change to get the properties dialog for all files and folder of a specified drive. Perhaps getting all folders/files of the drive into an array and then working with that?
Please note I'm looking for the actual properties dialog, and not just a simple return of the total number of files (I know how to do this).
Any help would be appreciated! Thanks :)
Code:
dim objShell, objFSO, folParent, sParent, filTarget, sFileName, sOutput, fivVerbs, iVerb, vVerb, fvbVerb, testItemsParent, TestMappedDestination
set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Shell.Application")
const mappedDestination = "c:\"
vVerb = "P&roperties"
sParent = objFSO.GetParentFolderName(mappedDestination)
sFileName = objFSO.GetFileName(mappedDestination)
If Len(mappedDestination) = 3 then
nsTarget = &H11
TestMappedDestination = "(" & UCase(Left(mappedDestination,2)) & ")"
Else
nsTarget = sParent
TestMappedDestination = UCase(sFileName)
End If
set folParent = objShell.Namespace(nsTarget)
For each filTarget in folParent.Items
If Len(mappedDestination) = 3 then
testItemsParent = UCase(Right(filTarget,4))
Else
testItemsParent = UCase(filTarget)
End if
If testItemsParent = TestMappedDestination then
Set fivVerbs = filTarget.Verbs
For iVerb = 0 to fivVerbs.Count - 1
If fivVerbs.Item(iVerb).Name = vVerb then
Set fvbVerb = fivVerbs.Item(iVerb)
fvbVerb.DoIt()
filTarget.InvokeVerbEx fvbVerb.Name, ""
Msgbox "Placeholder msgbox to keep properties dialog/sheet from disappearing on script completion"
Exit for
End if
Next
Exit for
End if
Next
The code below looks in the test folder for any files that have not been accessed in over 5 days, if it finds one it assigns mRoot the file path and then whats NOT WORKING is using the Replace method to look inside the mRoot string for the IP and replace it with the new one, I have it show me what mRoot looks like in a pop up just to make sure it changes(or doesn't). I can't seem to get the IP to change. Can anyone help out? I'm very new to VBS so I'm hoping this is obvious (whether it is doable or not). Thanks.
Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")
sRoot = "\\192.168.1.104\test\"
today = Date
Set aFolder = oFileSys.GetFolder(sRoot)
Set aFiles = aFolder.Files
For Each file in aFiles
FileAccessed = FormatDateTime(file.DateLastAccessed, "2")
If DateDiff("d", FileAccessed, today) > 5 Then
Set objShell = Wscript.CreateObject("Wscript.Shell")
mRoot = file
Call Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")
objShell.Popup mRoot,, "My Popup Dialogue box"
'oFileSys.MoveFile file, mRoot
End If
Next
Try mRoot = Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")