I'm relatively new to PowerShell, and I tried to copy files using a text file formatted as follows:
file1.pdf
dir1\dir2\dir3\dir 4
file2.pdf
dir1\dir5\dir7\di r8
file3.pdf
...etc.
If the first line of each record is the file name, and the second is the file path from C: \ Users. For example, the full path to the first entry in the file:
C:\Users\dir1\dir2\dir3\dir 4\file1.pdf
Below is the code that I have, but I get an error: "This path format is not supported." and another mistake after that tells me that he cannot find the path that I guess is the result of the first error. I played a little with him, and I get the impression that this has something to do with passing the Copy-Item string.
$file = Get-Content C:\Users\AJ\Desktop\gdocs.txt
for ($i = 0; $i -le $file.length - 1; $i+=3)
{
$copyCommand = "C:\Users\" + $file[$i+1] + "\" + $file[$i]
$copyCommand = $copyCommand + " C:\Users\AJ\Desktop\gdocs\"
$copyCommand
Copy-Item $copyCommand
}
source
share