8 posts in this topic
I have an ini file which has structure as below.
And I want to use this value and change only the file name in below path of another ini file.
Can you suggest any approach.
Let's say I get a path called "E:\pics\". It has pictures inside which are numbered starting at 0. Then we get something like "E:\pics\0" or "E:\pics\1" or "E:\pics\2"... The amount of numbers, thus the path of the last picture, are known to me already. For example, there are 100 pictures, which means that the files start at 0 and end at 99
However, for some things that isn't enough, because they need the file extension. They can be pretty "random", though. Sometimes it's a JPG, sometimes it's a PNG, sometimes it's a GIF.
So, I know need some kind of function that gets me the file extension, or the complete path, from an incomplete path. The input would be "E:\pics\1" and I expect and output of "E:\pics\1.jpg" for example.
Also, there is just one file extension per number. For example, it there is "E:\pics\1.jpg", there won't be a "E:\pics\1.png" anymore.
And this will be looped as well. First I get number 0, then number 1, then number 2, and so on. So I need something that is able to be repeated in a for-loop without causing problems with the parameters.
Thanks a lot!
How to select a folder and assign the path value to a variable in autoit?
; Selecting a file and assigning that to $sPath value) Case $file $sPath = FileOpenDialog("Open a file", @desktopdir, "Cabinet Files (*.cab)",$FD_MULTISELECT) GUICtrlSetData($file, $sPath) ; How to do the same with a folder? Case $folder $sPath = FileSelectFolder($sPath, "") Need the selected folder path to be used in the $sPath section for further implementation.
Or a method to Select Folder or Files at once.
I'm automating a commercial app that will copy files/folders from an optical disc to a folder on a hard drive, and am unable to check an item in a SysTreeView32 control in the app's main window. The disc and its top-level folders are displayed as a simple tree, and I've written a test script that probes and manipulates the control by calling ControlTreeView(). The script cannot, on its own, check the desired item in the TreeView, but it can check the item with some manual intervention. I need to know if there's something missing, or if a different approach is needed.
The operations currently being tested are:
Waiting until the contents of the TreeView control appear before proceeding (the app can take a long time to display the control contents), and Checking the first item's checkbox (i.e., the disc itself), thus selecting the entire disc contents for copying. The test script can complete the first operation successfully, but not the second: there is a side-effect of the first that apparently causes the second one to fail.
When the control's contents eventually become visible, they look like this; note the position of the scrollbar:
The wait is done by repeatedly selecting the first item until @error=0 using the following code fragment (note: the code has been edited for brevity and to remove certain information):
; Wait for the DM window to become active ; -- _WinWaitActivate() is from AU3 Recorder-generated code $hWnd1 = _WinWaitActivate($sDMtitle,"") ; Wait for the SysTreeViewList32 control to display its first item $sCtrlAdvMode = "[CLASS:SysTreeView32; INSTANCE:1]" $i = 0 $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Select","#0") $iAtError = @error While $iAtError <> 0 $i += 1 If $i > 20 Then ExitLoop Sleep(5000) $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Select","#0") $iAtError = @error WEnd If $i > 20 Then ConsoleWrite("Select: Unable to select 1st item after 20 tries" & @CRLF) This works - the script successfully loops until the contents are visible, but when the item selection finally succeeds, the control contents scroll horizontally, hiding the checkboxes:
The script then tries to check the first item by calling ControlTreeView() from the following code fragment (again, edited for brevity, etc.):
; Check the first item $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Check","#0") If @error <> 0 Then ConsoleWrite("Check: Unable to check 1st item, return=" & $iRetVal & ", @error=" & @error & ", @extended=" & @extended & @CRLF) $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"IsChecked","#0") ConsoleWrite("IsChecked: return=" & $iRetVal & ", @error=" & @error & ", @extended=" & @extended & @CRLF) The Check call always returns @error=1, and the IsChecked call returns without error, but with a value of False. (The boxes remain unchecked on the screen as well.)
HOWEVER: With some experimentation I discovered that if I put a pause in the test script so that I can manually scroll the TreeView to make the checkboxes visible, then the Check call works - the boxes in the control are all checked, and the IsChecked call returns True.
Any suggestions for making this work under program control (no manual intervention)? The application needs to be completely automated.
Note: I have tried another method for the wait-loop (getting the first item's checkbox value), hoping it would achieve the desired result without scrolling the tree. However, the IsChecked call returns with @error=0 (and False) on the first call, long before the tree was visible.
I'm looking for a good regex to get the drive letter and the last two folders from a file path,
If the path is to long for the label width then show drive + ellipses and two last folders.
and when the folder is in the root of the drive then show D:\Folder
The test GUI
#cs ---------------------------------------------------------------------------- AutoIt Version: 188.8.131.52 Author: Mecano Script Function: ELLIPSIS Long path: Drive:\...\Folder\Folder if root then Drive:\Folder #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $sFile = "F:\Just a folder\in a another folder\and another\This-dir\And-this-dir" $EllipsisPath = StringRegExpReplace($sFile, '\w[a-zA-Z \\]+\\', '') ; <- This needs another regex ;no ellipsis needed, for testing purposes only $sUSB = "K:\Just a folder" $PathforUSB = StringRegExpReplace($sUSB, '\w[a-zA-Z \\]+\\', '') #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Drive + Two last folders of path", 327, 236, 192, 124) $Button1 = GUICtrlCreateButton("Test label", 40, 168, 97, 33) $Label1 = GUICtrlCreateLabel("F:\...\This-dir\And-this-dir", 40, 12, 200, 40) ; <- Looks good but not dynamic GUICtrlSetColor($Label1, 32768) $Label2 = GUICtrlCreateLabel($sFile, 40, 40, 200, 40, $DT_END_ELLIPSIS) ; <- not the last two directorys GUICtrlSetColor($Label2, 16711680) $Label3 = GUICtrlCreateLabel("Var label1", 40, 72, 200, 40) GUICtrlSetColor($Label3, 16711680) $Label4 = GUICtrlCreateLabel("Var label", 40, 104, 200, 40) GUICtrlSetColor($Label4, 16711680) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetData($Label3, $EllipsisPath) ; $DT_END_ELLIPSIS <- works only on GUICtrlCreateLabel GUICtrlSetData($Label4, $PathforUSB) EndSwitch WEnd
Thanks in advance