Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell Script Prompt 2 input in one go

i wanted to make one prompt to ask for 2 input in one go for e.g "D:\Test\File 1", "D:\Test\File 2
instead of this input first file path: "D:\Test\File 1", input second file path: "D:\Test\File 2".

function compareTwoFiles($firstFilePath, $secondFilePath) 
{
$firstFilePath = Read-Host "Input first file path" 
$secondFilePath = Read-Host "Input second file path"

if ($firstFilePath.Length -gt $secondFilePath.Length)
    {"File 1"}
elseif ($firstFilePath.Length -lt $secondFilePath.Length)
    {"File 2"}
else {"both file has same size"}
return
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

try to do this, input the file path and separate them with ";" or "-" or any other char, then split the input like this:

$input = Read-Host "Input first file path, place ';' and then other file path " 
$userInputs = $input.Split(";")

$userInputs[0]
$userInputs[1]

The output:

PS C:\Users\Awat\Desktop\testPS> .\myscript.ps1
Input first file path, place ';' and then other file path : file1.txt;file2.txt
file1.txt
file2.txt
PS C:\Users\Awat\Desktop\testPS>

your code should be similar to this:

$input = Read-Host "Input first file path, place ';' and then other file path " 
$userInputs = $input.Split(";")

// Just for output....
$userInputs[0]
$userInputs[1]

if ($userInputs[0].Length -gt $userInputs[1].Length)
    {"File 1"}
elseif ($userInputs[0].Length -lt $userInputs[1].Length)
    {"File 2"}
else {"both file has same size"}
return
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading