Hi,
Had posted viewtopic.php?f=21&t=14044 regarding opening a Windows file, f.e. examplefile.XMind via a Powershell Studio form (exe). Result should then be that the form opens and shows
ExampleFile.XMind.
There was an answer
cmd /c assoc /?
cmd /c ftype /?
but honestly didn't have a clue what to do with that, so googled a bit, found nothing and left it. The post is now locked. Therefore a second attempt.
Please advise the steps to take:
1.I create a Powershell form
2.I save it as an exe
3.I open the ExampleFile.XMind with that exe
What should be in that exe/form that shows me the output
ExampleFile.XMind so I can capture it in a variable and work with it?
How do I give the ExampleFile.Xmind to the exe then in the code?
Note: associations of the file .Xmind to Xmind program is none of my worries right now.
Please advise.
J.
Send a file to Powershell Studio exe (form): show name and extension
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Send a file to Powershell Studio exe (form): show name and extension
>No idea what you are trying to ask.
Sorry bout that Let me try again. Hopefully the screenshot of what I'm trying to do clarifies it.
If not, do let me know!
Sorry bout that Let me try again. Hopefully the screenshot of what I'm trying to do clarifies it.
If not, do let me know!
Re: Send a file to Powershell Studio exe (form): show name and extension
Thanks, tried this:
$form1_Load={
#TODO: Initialize Form Controls here
$labelFileYouOpenedWithExe.Text = $args[0]
}
But the label in the form doesn't show the filename when opened the ExampleFile.XMind with the exe (generated from PSStudio).
Should I change the output options?
$form1_Load={
#TODO: Initialize Form Controls here
$labelFileYouOpenedWithExe.Text = $args[0]
}
But the label in the form doesn't show the filename when opened the ExampleFile.XMind with the exe (generated from PSStudio).
Should I change the output options?
Re: Send a file to Powershell Studio exe (form): show name and extension
Taking all defaults build this:
- Attachments
-
- Test-FormArgs.psf
- (9.07 KiB) Downloaded 107 times
Re: Send a file to Powershell Studio exe (form): show name and extension
Thanks! Will check right away.
Re: Send a file to Powershell Studio exe (form): show name and extension
Works great, thanks!!!
However, I cannot detect the extension correctly, though it is there.
$FullPathOfFile = [System.IO.Path]::GetFullPath($commandarg)
$FileName = $(split-path $FullPathOfFile -Leaf)
$Global:Extension = $([System.IO.Path]::GetExtension($FileName).tostring()).trim()
$textboxFileExtension.Text = $Extension
if ($Extension -eq '.xmind') { $textboxResult.Text = 'XMind is the program you could open .XMind with'}
else {$textboxResult.Text = 'no program found'}
Please advise on this (it just shows "no program found"}.
Thanks!
However, I cannot detect the extension correctly, though it is there.
$FullPathOfFile = [System.IO.Path]::GetFullPath($commandarg)
$FileName = $(split-path $FullPathOfFile -Leaf)
$Global:Extension = $([System.IO.Path]::GetExtension($FileName).tostring()).trim()
$textboxFileExtension.Text = $Extension
if ($Extension -eq '.xmind') { $textboxResult.Text = 'XMind is the program you could open .XMind with'}
else {$textboxResult.Text = 'no program found'}
Please advise on this (it just shows "no program found"}.
Thanks!
Re: Send a file to Powershell Studio exe (form): show name and extension
This is the correct way to do this in PowerShell.
Code: Select all
# get file information
$file = [io.fileinfo]$commandarg
$file.FullName
$file.Name
$file.Basename
$file.DirectoryName
$file.Extension
#or
([io.fileinfo]$commandarg).Extension
# get directory details
$file.Directory.FullName
# get all properties:
$file | select *
Re: Send a file to Powershell Studio exe (form): show name and extension
Code: Select all
if (([io.fileinfo]$commandarg).Extension -eq '.xmind') {
$textboxResult.Text = 'XMind is the program you could open .XMind with'
} else {
$textboxResult.Text = 'no program found'
}