Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 762925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:28:35+00:00 2026-05-14T16:28:35+00:00

During investigation of some problem I found that the reason was unexpected different conversion

  • 0

During investigation of some problem I found that the reason was unexpected different conversion to string[] of seemingly same input data. Namely, in the code below two commands both return the same two items File1.txt and File2.txt. But conversion to string[] gives different results, see the comments.

Any ideas why is it? This might be a bug. If anybody also thinks so, I’ll submit it. But it would nice to understand what’s going on and avoid traps like that.

# *** WARNING
# *** Make sure you do not have anything in C:\TEMP\Test
# *** The code creates C:\TEMP\Test with File1.txt, File2.txt

# Make C:\TEMP\Test and two test files
$null = mkdir C:\TEMP\Test -Force
1 | Set-Content C:\TEMP\Test\File1.txt
1 | Set-Content C:\TEMP\Test\File2.txt

# This gets just file names
[string[]](Get-ChildItem C:\TEMP\Test)

# This gets full file paths
[string[]](Get-ChildItem C:\TEMP\Test -Include *)

# Output:
# File1.txt
# File2.txt
# C:\TEMP\Test\File1.txt
# C:\TEMP\Test\File2.txt
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:28:35+00:00Added an answer on May 14, 2026 at 4:28 pm

    Well, I have got some clues (probably posting the question stimulated my thoughts). Yes, this is kind of a trap, not only in PowerShell (but PowerShell makes it possible).

    Apparently PowerShell just uses ToString() for conversion. And it was a wrong assumption that System.IO.FileInfo.ToString() returns the FullName. Reflector shows that it returns the base.OriginalPath which is just what was passed in the constructor, not necessary a full path.

    Here is the demo:

    Set-Location C:\TEMP\Test
    [string](New-Object IO.FileInfo File1.txt)
    [string](New-Object IO.FileInfo C:\TEMP\Test\File1.txt)
    [string](New-Object IO.FileInfo ./..//Test///..Test\File1.txt)
    
    # Output:
    # File1.txt
    # C:\TEMP\Test\File1.txt
    # ./..//Test///..Test\File1.txt
    

    Thus, it looks like the first Get-ChildItem uses just names on creation of FileInfo objects and the second Get-ChildItem with the –Include parameter uses full paths. Is this a bug? It looks debatable now. It might be a feature, questionable, but still with some underlying reasons. I doubt, though…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having issues while passing objects across Appdomains.During further investigation I found that
I'm working on Android applications which uses SensorManager for different purposes. During investigation I
During an interview I was asked if there can be some object that will
During a typical day programming, I implement functions in a way that I would
During an ASP.NET page load I'm opening and closing multiple System.Data.SqlClient.SqlConnections inside multiple controls
During my apprenticeship, I have used NHibernate for some smaller projects which I mostly
During my work with databases I noticed that I write query strings and in
During conversion old, 2008 database project into 2010 database project using features like Partial
During a recent peer review, another Software Engineer suggested that I state that the
While debugging some C# code during a sort of peer-review, I noticed an odd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.