Hello all,
Ive pasted the relevant bit of code below. For some reason, Im getting these errors, saying it cant move the items because they dont exist. This confuses me, because how could they not exist? Ive copied all items in my Documents
folder, moved them to Win213copy
, and then moved them again, into different subfolders.
Here are the errors: http://imgur.com/a/zAVd2
(Also, why does my $count
variable not list the number of files moved? 😓)
Thanks in advance, guys:
## Search Documents folder recursively for files only and save them to a new directory called Win213Copy New-Item -path $homedocumentswin213 -ItemType Directory -Name Win213copy -Force $files = Get-ChildItem -Recurse -file $homedocuments $files | Copy-Item -destination 'C:UsersMishaDocumentsWin213Win213copy' -Force ## Get a listing of the files in the Copy folder and move them to the appropriate subfolder $copyListing = Get-ChildItem Win213copy $count = 0 foreach ($dir_File in $copyListing){ if ($dir_File -like '*lab*'){ Move-Item $dir_File -Destination C:UsersMishaDocumentsWin213Labs -Force $count ++ } if ($dir_File -like '*lec*'){ Move-Item $dir_File -Destination C:UsersMishaDocumentsWin213Lectures -Force $count ++ } if ($dir_File -like '*assign*'){ Move-Item $dir_File -Destination C:UsersMishaDocumentsWin213Assignments -Force $count ++ } if ($dir_File -like '*.ps1*'){ Move-Item $dir_File -Destination C:UsersMishaDocumentsWin213Scripts -Force $count ++ } }
submitted by /u/chy_vak
[link] [comments]
The post Error messages being tossed out, is it the logic in the code? appeared first on How to Code .NET.