Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get all QMitem in the folder where the current macro
#1
I want to get all QMitem in the folder where the current macro. If there are multiple folders with the same name, only the projects under the parent folder should be retrieved.
demo: https://i.ibb.co/G4G9WCzp/demo.gif

How to get the folder path in the format like "\Folder\Folder"?

Macro C
Code:
Copy      Help
out

QMITEM qi
qmitem("" 0 &qi)
str folderName.getmacro(qi.folderid 1)
out folderName

ARRAY(QMITEMIDLEVEL) a; int i
GetQmItemsInFolder(folderName &a 1)
for i 0 a.len
,out _s.getmacro(a[i].id 1)
#2
The following qm code can generate the following file hierarchy after execution.
[Folder]
.A
.B
.[Folder]
..C
..D
Macro18
Macro17


How to generate a file hierarchy like this? It seems that this file structure could solve my problem(I can search for \qmitemName to find the folder where it is located).
[Folder]
[Folder]\A
[Folder]\B
[Folder]\[Folder]
[Folder]\[Folder]\C
[Folder]\[Folder]\D
Macro18
Macro17


Link: https://www.libreautomate.com/forum/show...6#pid17056
Macro GetQmItemNames_T
Code:
Copy      Help
out
str s
GetQmItemNames "" s
out s

The following post is similar to the problem I encountered.

https://www.libreautomate.com/forum/show...p?tid=4612
#3
Can anyone help? Thank you very much.  

I even thought about using PowerShell to implement the above functionality.  Big Grin

It would be great if the GQIN_Enum function in the following link could be improved to output the full path, such as [Folder]\[Folder]\qmitemName.
https://www.libreautomate.com/forum/show...6#pid17056
 
Code:
Copy      Help
$lines = @'
[Folder]
.A
.B
.[Folder]
..C
..D
Macro18
Macro17
'@ -split "`r`n"

# Stack for tracking the current multi-level directory
$stack = @()

foreach ($line in $lines) {
    $trimmed = $line.Trim()
    if ($trimmed -eq "") { continue }

    # Determine the number of dots
    if ($trimmed -match '^(\.+)(.+)$') {
        $level = $Matches[1].Length
        $name = $Matches[2].Trim()

        # Ensure the stack depth matches the level; pop if too deep, keep if less
        if ($stack.Count -gt $level) {
            $stack = $stack[0..($level-1)]
        }

        # If it's a folder (starts with dots and [xxx]), push to stack and output
        if ($name -match '^\[(.+)\]$') {
            $stack += $Matches[0]
            Write-Output ($stack -join '\')
        } else {
            # Regular file, output full path directly
            Write-Output (($stack -join '\') + "\" + $name)
        }
        continue
    }

    # Top-level folder, reset stack
    if ($trimmed -match '^\[(.+?)\]$') {
        $stack = @($Matches[0])
        Write-Output $trimmed
        continue
    }

    # Regular top-level item (no indentation)
    Write-Output $trimmed
}


Forum Jump:


Users browsing this thread: 1 Guest(s)