Powershell navigating to unknown directory - powershell

I have stumbled the unfortunate situation, having to be in a directory in which another directory is located:
C:\Test\[Folder with unknown name]\theFileINeed.txt
The structure mentioned above originates from a Zip-file from an external source. So i can not change the structure.
My goal is to navigate to the Directory with the unknown name, so it is my working directroy and I can execute further commands there. (Like Get-Childitem e.g.)
Is there a simple way to e.g. use the cd command to move into that directory?
I have fiddled around a bit with Resolve-Path but couldn't find a helpful solution.
Thanks in advance.

Consider this structure:
C:\TMP\TEST
├───unknowndir1
│ │ nonuniquefile.txt
│ │ uniquefile.txt
│ │
│ ├───nonuniquesubdir
│ └───uniquesubdir
└───unknowndir2
│ nonuniquefile.txt
│
└───nonuniquesubdir
You could do cd .\test\*\uniquesubdir but you can't cd .\test\*\nonuniquesubdir as you'll gen an error (...) path (...) resolved to multiple containers. The same error is even with cd .\test\*\uniquesubdir\.. as if it didn't even check for existence of uniquesubdir.
So if you want to enter unknown directory based of a file it contains, you'd have to do something like this: cd (Get-Item .\test\*\uniquefile.txt).DirectoryName.
It will fail if you use nonuniquefile.txt as it again resolves to two different directories. You could enter the first of these directories with cd (Get-Item .\test\*\nonuniquefile.txt).DirectoryName[0] if you don't care which of them you use.

Related

Flutter - how to run script from relative path

I have a .vbs script inside the flutter project that I'd like to run after the press of the button. I have verified, that the script works if path to it is provided as an absolute. However, for some mysterious reason, it does not work when I change the path to relative. I am losing my mind, am I doing anything wrong? Is there any other way how to solve this? (Maybe placing the script to the assets)?
Directory structure is following:
lib
│
└───screens
│ │ destination_selection_screen.dart
│
└───scripts
│ runAssemblySyncHidden.vbs
I would like to run runAssemblySyncHidden.vbs from the destination_selection_screen.dart so logically my relative path looks like this:
onPressed: () async {
final process = await Process.start(
'..\\scripts\\runAssemblySyncHidden.vbs', [],
runInShell: true);
}
Unfortunately, does not seem to work. But when I provide an absolute path to the script, it does. Any help appreciated.
start runAssemblySyncHidden.vbs

Can't get diff output from NestedStack in AWS CDK

I have an issue when I'm working with NestedStack in AWS CDK, the problem is when I'm using the cdk diff command its returns the diff output return to me.
But when I have a diff inside my NestedStack it's just a reference and i really don't know what it will change inside my NestedStack.
[~] AWS::CloudFormation::Stack IAMPolicyStack.NestedStack/IAMPolicyStack.NestedStackResource IAMPolicyStackNestedStackIAMPolicyStackNestedStackResource4B98A1D2
├─ [~] NestedTemplate
│ └─ [~] .Resources:
│ └─ [~] .CDKMetadata:
│ └─ [~] .Properties:
│ └─ [~] .Analytics:
│ ├─ [-] v2:deflate64:H4sIAAAAAAAA/zPSMzLWM1BMLC/WTU7J1s3JTNKr9kstLklNCS5JTM7WcU7LC0otzi8tSk4FsZ3z81IySzLz82p1AipLMvLz9I31DA30TBSzijMzdYtK80oyc1P1giA0AJZoScZcAAAA
│ └─ [+] v2:deflate64:H4sIAAAAAAAA/zPSMzLWM1BMLC/WTU7J1s3JTNKr9kstLklNCS5JTM7WcU7LC0otzi8tSk4FsZ3z81IySzLz82p1AipLMvLz9I31LPUMjRSzijMzdYtK80oyc1P1giA0ALbtmvJcAAAA
Hope someone out there has hit the same issue as me and has a solution about how to get the diff output from NestedStack.
Updated 30/05/2022
The featuer look like its not ready yet, but its coming in the feature based my ticket here - https://github.com/aws/aws-cdk/issues/20392
This commit adds a workaround where you can run
cdk deploy --no-execute
and then view the nested stack changes in the CloudFormation change set that gets created.
Edit: Looks like this has not been merged yet as of 1.163.1, here is the open issue.

what is the purpose of dbus interface xml file?

I am reading D-Bus API Design Guidelines:
Interface files for public API should be installed to $(datadir)/dbus-1/interfaces so that other services can load them.
OK... in order to understand how these interface files work, I open the file /usr/share/dbus-1/interfaces/org.gnome.Shell.Screenshot.xml (I'm using Ubuntu 20.04)
<node>
<interface name="org.gnome.Shell.Screenshot">
...
<method name="PickColor">
<arg type="a{sv}" direction="out" name="result"/>
</method>
Well, I see the interface name, I see the method name, but that is not enough. If I want to call this method using dbus-send
$ dbus-send --print-reply --dest=<service.name> </path/to/object> org.gnome.Shell.Screenshot.PickColor
I need <service.name> and <path/to/object>, which this xml-file does not provide.
The queston is: what is the purpose of this file if it does not provide full information about the service interface? Is it used by dbus-daemon or by any other programs? Are such files really needed for something? Should I make a conclusion that an xml-file, which does not provide a path to object in , is incomplete? Should such file also mention a service known name (org.gnome.Shell.Screenshot in this case)?
The org.freedesktop.DBus.Introspectable interface has one method:
org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)
Object instances may implement Introspect which returns an XML description of the object. The introspection format is documented at:
https://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
Using busctl on the command line I can use list to get all the services, tree to get all the objects, and then intropspect to find the API. Using these three commands I can discover the D-Bus services on a system
$ busctl list
$ busctl tree <service>
$ busctl introspect <service> <object>
The service you mentioned in your question is on the Session/User bus so it would be:
$ busctl --user list | grep Screenshot
NAME PID PROCESS USER CONNECTION UNIT SESSION DESCRIPTION
---------------------------------------------------------------------------------------------------------------------------------
org.gnome.Screenshot - - - (activatable) - - -
org.gnome.Shell.Screenshot 1259 gnome-shell LinuxMachine1 :1.37 user#1000.service - -
$ busctl --user tree org.gnome.Shell.Screenshot
├─/StatusNotifierWatcher
└─/org
├─/org/freedesktop
│ ├─/org/freedesktop/Notifications
│ └─/org/freedesktop/portal
│ └─/org/freedesktop/portal/desktop
├─/org/gnome
│ ├─/org/gnome/Mutter
│ │ ├─/org/gnome/Mutter/DisplayConfig
│ │ └─/org/gnome/Mutter/IdleMonitor
│ │ └─/org/gnome/Mutter/IdleMonitor/Core
│ ├─/org/gnome/ScreenSaver
│ ├─/org/gnome/SessionManager
│ │ └─/org/gnome/SessionManager/EndSessionDialog
│ ├─/org/gnome/Shell
│ │ ├─/org/gnome/Shell/AudioDeviceSelection
│ │ ├─/org/gnome/Shell/Introspect
│ │ ├─/org/gnome/Shell/Screencast
│ │ ├─/org/gnome/Shell/Screenshot
│ │ └─/org/gnome/Shell/Wacom
│ └─/org/gnome/keyring
│ └─/org/gnome/keyring/Prompter
└─/org/gtk
├─/org/gtk/MountOperationHandler
└─/org/gtk/Notifications
$ busctl --user introspect org.gnome.Shell.Screenshot /org/gnome/Shell/Screenshot
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
org.gnome.Shell.Screenshot interface - - -
.FlashArea method iiii - -
.PickColor method - a{sv} -
.Screenshot method bbs bs -
.ScreenshotArea method iiiibs bs -
.ScreenshotWindow method bbbs bs -
.SelectArea method - iiii -
And for completeness, running the same command as you did:
$ busctl --user call org.gnome.Shell.Screenshot /org/gnome/Shell/Screenshot org.gnome.Shell.Screenshot PickColor
a{sv} 1 "color" (ddd) 1 1 1
The answer is in the name: it’s a D-Bus interface file. It defines an interface, not an instantiation of that interface. There may be zero or more instantiations of an interface in D-Bus, and they may be dynamic. So their paths can’t be specified in an XML file.
If D-Bus was designed now, perhaps this XML file would have been structured or implemented differently. But this is what there is.

connect to kdb+ DB from a .q file

I am using kdb+ & nodeJS. I need to send queries from node to the db.
when I cd to the "db" directory and type q db I have candles set.
I created inside "db" folder a file called startServer.q:
\p 8080
h:hopen `:localhost:8080:user:pass
When I run startServer.q it opens but it seems that the candles variable is not set.
How can I access this table from that file? didn't find anything on the internet.
When you cd into the db folder and run q startServer.q the variable candles will not be set because it has not been loaded in, you just need to do:
q) \l /path/to/db
after you do q startServer.q and it will load in the table(s) in the db folder.
It would be a good idea to have startServer.q and db folder at the same level in your directory, i.e.
.
├── parent-directory
│ ├── db
│ └── startServer.q
then you could add the line
system["l db"];
to your startServer.q file and it would load in when you do q startServer.q.

Maintain SubSubFolder structure While Merging into Another Folder [Duplicate FolderNames Will Exist]

I currently receive emails for tickets and responses. They are automatically sent to folders as pdf. I create cover pages for them. So essential 3 sections that will eventually become one big pdf (cover, ticket, & response).
Ticket numbers are 14 digits and usually the emails contain that ticket number somewhere in the subject line (which is the pdf title). So I use BulkRenameUtility and Regex to rename every ticket to the 14 digit ticket number, with "-Ticket" after it. All responses then get named to the 14 digit ticket number, prefixed with a 2 (so that pdftk combines it last), and if there is multiple responses sequentially numbered. All covers are automatically generated with "10A-" then the 14 digit ticket number, then the job number. Ticket numbers are in the format YYMMDDHHNN####. So that makes pdftk compile these as Cover, ticket, then response.
But before pdftk can combine the pdfs into one. I need them to be in the same folder. I use a batch script to sort all covers into a folder with the 14 digit ticket name as the foldername, the same for the responses and tickets. So i end up with (depending on the number of tickets, right now I have 96) many subfolders like this.
.....OpenLocates
..........Current
...............Complete
....................[EMPTY]
...............Covers #There will be one cover per job.
....................18051400000001
.........................10A-18051400000001_218001.pdf
....................18051400000002
.........................10A-18051400000002_217022.pdf
...............Responses #There will be multiple responses per ticket.
....................18051400000001
.........................218051400000001.pdf
.........................218051400000001_1.pdf
.........................218051400000001_2.pdf
....................18051400000002
.........................218051400000002.pdf
.........................218051400000002_1.pdf
.........................218051400000002_2.pdf
...............Tickets #There *can* be multiple tickets per job.
....................18051400000001
.........................18051400000001-Ticket.pdf
....................18051400000002
.........................18051400000002-Ticket.pdf
What I need is for all those subfolders to merge into one. There should not ever be a duplicate filename since BRU does sequentially number duplicates when renaming the pdf files in the first place.
.....OpenLocates
..........Current
...............Complete
....................18051400000001
.........................10A-18051400000001_218001.pdf
.........................18051400000001-Ticket.pdf
.........................218051400000001.pdf
.........................218051400000001_1.pdf
.........................218051400000001_2.pdf
....................18051400000002
.........................10A-18051400000002_217022.pdf
.........................18051400000002-Ticket.pdf
.........................218051400000002.pdf
.........................218051400000002_1.pdf
.........................218051400000002_2.pdf
The batch script is this:
#echo on
::CALLALL
Call :SortCovers
Call :SortResponses
Call :SortTickets
goto :EOF
:SortCovers
cd L:\OpenLocates\Current\Covers
for /f %%a in ('dir /a-d /b') do (
if not "%%~dpnxa"=="%~dpnx0" call :SortCoversFunction "%%~a"
)
goto :EOF
:SortCoversFunction
set file=%~1
set dir=%file:~4,14%
md "%dir%" 2>nul
move "%file%" "%dir%"
goto :EOF
:SortResponses
cd L:\OpenLocates\Current\Responses
for /f %%a in ('dir /a-d /b') do (
if not "%%~dpnxa"=="%~dpnx0" call :SortResponsesFunction "%%~a"
)
goto :EOF
:SortResponsesFunction
set file=%~1
set dir=%file:~1,14%
md "%dir%" 2>nul
move "%file%" "%dir%"
goto :EOF
:SortTickets
cd L:\OpenLocates\Current\Tickets
for /f %%a in ('dir /a-d /b') do (
if not "%%~dpnxa"=="%~dpnx0" call :SortTicketsFunction "%%~a"
)
goto :EOF
:SortTicketsFunction
set file=%~1
set dir=%file:~0,14%
md "%dir%" 2>nul
move "%file%" "%dir%"
goto :EOF
Right now i'm cut/pasting the folders and clicking OK on the merge popup in windows explorer.
But i have to teach my whole process to another person next week, and i'd like to simplify it down.
After I have all my folders merged I run a powershell script with PDFTK to combine the pdf files and save them in the parent folder.
I could really use some help on getting the subfolders of Covers, Responses and Tickets to move out to the Complete folder merging the duplicate foldernames to create one folder with all my files for each ticket number so I can run the following powershell script that does successfully combine them in the correct order.
$pdftk = "C:\SymLinks\Combine\pdftk.exe"
$inputFolder = "L:\OpenLocates\Current\Complete"
gci $inputfolder -r -include *.pdf | sort-object | group DirectoryName | % {& $PDFtk $_.group CAT OUTPUT "$($_.Name | Split-Path -Parent)\$($_.Name | Split-Path -Leaf).pdf" verbose}
Any help would be greatly appreciated. I've tried several different batch and powershell scripts and none seem to be working for me.
Edit: I do combine all the ticket numbers for one job into one folder before combining the PDFs. All the folders get renamed to the job name also before combining that final PDF.
I'd stay with the more modern script langugage.
I created a test environment on my ramdisk A:
## Q:\Test\2018\05\19\SO_50419164.ps1
$Sources = ("A:\OpenLocates\Current\Covers\",
"A:\OpenLocates\Current\Responses\",
"A:\OpenLocates\Current\Tickets\")
$Target = "A:\OpenLocates\Current\Complete\"
ForEach ($Source in $Sources){
Get-ChildItem $Source -Directory | ForEach-Object {
$TargetSub = Join-Path $Target $_.Name
If (!(Test-Path $TargetSub)){ MD $TargetSub |Out-Null}
Get-ChildItem $_.FullName -File | Move -Dest $TargetSub
Remove-Item $_.FullName
}
}
Tree a: /F before
A:\
└───OpenLocates
└───Current
├───Complete
├───Covers
│ ├───18051400000001
│ │ 10A-18051400000001_218001.pdf
│ │
│ └───18051400000002
│ 10A-18051400000002_217022.pdf
│
├───Responses
│ ├───18051400000001
│ │ 218051400000001.pdf
│ │ 218051400000001_1.pdf
│ │ 218051400000001_2.pdf
│ │
│ └───18051400000002
│ 218051400000002.pdf
│ 218051400000002_1.pdf
│ 218051400000002_2.pdf
│
└───Tickets
├───18051400000001
│ 18051400000001-Ticket.pdf
│
└───18051400000002
18051400000002-Ticket.pdf
And after running the script:
A:\
└───OpenLocates
└───Current
├───Complete
│ ├───18051400000001
│ │ 10A-18051400000001_218001.pdf
│ │ 18051400000001-Ticket.pdf
│ │ 218051400000001.pdf
│ │ 218051400000001_1.pdf
│ │ 218051400000001_2.pdf
│ │
│ └───18051400000002
│ 10A-18051400000002_217022.pdf
│ 18051400000002-Ticket.pdf
│ 218051400000002.pdf
│ 218051400000002_1.pdf
│ 218051400000002_2.pdf
│
├───Covers
├───Responses
└───Tickets