Bird
0
0

Why does New-Item -Path 'C:\Test\file.txt' -ItemType File fail if the folder C:\Test does not exist?

hard📝 Conceptual Q10 of 15
PowerShell - File and Directory Operations
Why does New-Item -Path 'C:\Test\file.txt' -ItemType File fail if the folder C:\Test does not exist?
AFile creation requires -Force parameter
BNew-Item cannot create parent directories automatically
CThe path must be a directory, not a file
DPowerShell does not support file creation
Step-by-Step Solution
Solution:
  1. Step 1: Understand New-Item behavior with missing directories

    New-Item does not create missing parent directories automatically.
  2. Step 2: Analyze failure reason

    If 'C:\Test' folder is missing, New-Item cannot create 'file.txt' inside it and fails.
  3. Final Answer:

    New-Item cannot create parent directories automatically -> Option B
  4. Quick Check:

    Parent folders must exist before file creation [OK]
Quick Trick: Create parent folders before files with New-Item [OK]
Common Mistakes:
  • Assuming -Force creates missing folders
  • Thinking path must be directory for files
  • Believing PowerShell can't create files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes