0

I am trying to move files from the RootFolder to a subfolder via PowerShell (would like to keep SPItem.Id from changing if possible). The code I have used is pretty straight forward. starting to think the file is moving but the item isn't, causing them both to corrupt & go missing. Still not sure.

$web = get-spweb http://mySPweb.com
$list = $web.Lists["MyDocuments"]
$DestUrl ="/MyDocuments/SubFolderName/myfile.docx"
$file = $web.GetFile("/MyDocuments/myfile.docx")
$file.moveTo($DestUrl,$true)
$file.update()

I get no errors, the file object still exists. But checking via UI the folder is still empty

Late update:

The process used by the administrators to restore the DB for testing, corrupted the files. The above code works.

  • 1
    I've ran your script on my local install of SP2010 and it worked with no problems. What are the versioning settings for the document library? You may not be seeing the file in the UI if it is in a draft state and the library is set to only show drafts to content approvers. – Aquila Sands Apr 14 '14 at 10:46
1

Verify that your $file.Name is truly "myfile.docx".

Try these amended lines (with the other lines as is):

$DestUrl ="MyDocuments/SubFolderName/"
$file.MoveTo($DestUrl + $file.Name, true)
  • Still not working, I have also done.. $item = $web.Lists["MyDocuments"].GetItems()[4] $n = $item.Name $item.File.MoveTo("MyDocuments/SubFolderName/$n",$true) This point the files should have moved to the folder and be visible it is not. so I tried $item.File.Url which returns "MyDocuments/SubFolderName/myFile2.docx", $item.File.Item.url also returns "MyDocuments/SubFolderName/myFile2.docx", BUT $item.url still returns "MyDocuments/myFile2.docx". I have tried to call .update() on pretty much every object but still no change – user13186 Apr 12 '14 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.