1

I am new in Powershell. I tried to create the "dummy file" which is mentioned in the file.

For example, in the attached sheet, I have a file name called "Sheet" and there are total 5 files with different formats like - file1.pdf, file2.txt, file3.PNG, file4.docx, and file5.xlsx

I want to create the dummy file according to the file format.

So far I tried this code but it is not working. Please help me with it.

Thanks in advance

Screenshot: enter image description here

So far I tried this code but not working -

$file_list = Get-Content -Path "C:\Users\JamesAlam\Downloads\Sheet.txt"
$destination_folder = "C:\Users\JamesAlam\Downloads\Example"
$null = New-Item -Path $destination_folder -ItemType Directory -Force
foreach ($file in $file_list) {
     Copy-Item -Path $file -Destination $destination_folder -Recurse
}
2
  • 5
    Instead of Copy-Item you should use New-Item. ;-) Commented Oct 25, 2022 at 5:30
  • You need to be more clear about what qualifies a "dummy file". What's a dummy png file to you? What's a dummy docx file to you? Is a zero-bytes file just with the file extension acceptable? Or does it have to actually be a valid instance of that type of file? Commented Oct 25, 2022 at 5:41

1 Answer 1

4

You should usethe New-Item cmdlet to create the new files. Also, you can simplify your script. If you add -Force to the New-Item cmdlet, it will also create the directory structure:

$destination_folder = "C:\Users\JamesAlam\Downloads\Example"

Get-Content -Path "C:\Users\JamesAlam\Downloads\Sheet.txt" | ForEach-Object {
    New-Item -Path (Join-Path $destination_folder $_) -Force
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much mate.. appreciate your enormous help... this code is working perfectly :D

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.