1

here's my issue :

function Dummy ($path1, $fileName1) {
    Write-Host "$path1$fileName1"
}

Dummy 'folder\', 'test2.exe'

result is :

folder\ test2.exe

I have just no idea why this whitespace is added. I tried different formatting option (trim, string formatting, even native .net one without result).

Regex kind of work as a "post issue" but is too extrem fo my usage (folder with whitespace in name)

Note that those option i tried work perfectly (or should i say "as expected" -_-') OUT of the function.

if anyone could tell me how dumb i am i'd be glad -_-'

NB : i keep adding a simple "hi" first line of this thread, it just get removed everytime so, sorry for this.

2 Answers 2

2

It is because you are not sending in two parameters even though it might look that way. When you use a comma you are actually sending in an array. So $path will be an array with the values 'folder\' and 'test2.exe'. And of course $fileName1 will be empty.

So when you convert $path to a string the values will be separated by a space.

Remove the comma from the call and it will work:

Dummy 'folder\' 'test2.exe'

As a sidenote: I'm not quite sure what you are trying to do. But if you want to create paths I would recommend using:

Join-Path "folder" "test2.exe"
Sign up to request clarification or add additional context in comments.

1 Comment

well that was quick, and ... ty ! sidenote : tried the join-path way before posting here, but thanks to this array issue, i had the same kind of issue there. and i got you point about this :)
0

You have to do this:

function Dummy ($path1, $fileName1) {
    Write-Host "$($path1)$($fileName1)"
}

Dummy 'folder\', 'test2.exe'

1 Comment

Not working unfortunely, @Ostemar got it right thought !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.