Rename-Item for not empty folders

Welcome Forums General PowerShell Q&A Rename-Item for not empty folders

Viewing 6 reply threads
  • Author
    Posts
    • #228061
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Dear all,

      I’m just starting at this but I’m stuck in a very simple thing and “Google is not answering me”. I don’t have any knowlage about PowerShell, but sometimes I give a try on simple things to help me on daily basis problems. This week I was trying to upload around 23000 pics to Google Photos and… well, they don’t have any Folder organization system! So (maybe this was not a good decision) I decided to change my folder structure to make it easier for me to organize with albums later.

      I’ll try to explain what I want. Any idea, even to make it easier without any code, is welcome:

      My folders are like this (1):
      \Photos
      -2010
      –Home
      –Beach
      –Rio de Janeiro

      -2011
      –Home
      –Sao Paulo
      –Rio de Janeiro
      —Hotel
      —Beach
      –Panama
      ….

      What I tried to do was a simple “Rename-Item” to add, at least, the year at the beginning of every folder. Like this (2):
      \Photos
      -2010
      –2010-Home
      –2010-Beach
      –2010-Rio de Janeiro

      -2011
      –2011-Home
      –2011-Sao Paulo
      –2011-Rio de Janeiro
      —2011-Hotel
      —2011-Beach
      –2011-Panama
      ….

      Or, if possible, maybe combining the whole path in the name of the last path, like this (3):
      \Photos
      -2010
      –2010-Home
      –2010-Beach
      –2010-Rio de Janeiro

      -2011
      –2011-Home
      –2011-Sao Paulo
      –2011-Rio de Janeiro
      —2011-Rio de Janeiro-Hotel
      —2011-Rio de Janeiro-Beach
      –2011-Panama
      ….

      I tried to do the easier I could (2), adding only the yar at the begnnining, but it doesn’t change the name of the folder if there is any folder inside. It’s like “C:\Photos\2011\Rio de Janeiro\Hotel” for example.

      This is the “code” I tried. I don’t know how to make it look like a code:

      Thanks in advance for any help!

    • #228082
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Bom dia Peterson,

      You should use a nested loop …. maybe like this:

      … test with “test data” before, please. 😉

    • #228301
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Good Evening (Boa Noite), Olaf!

      First of all, thanks a lot for the prompt reply!

      Unhappilly, it didn’t work. I got an error at “Rename-Item” line. I’ll paste it here because maybe it helps. I believe that the code is not the problem. I am using PowerShell as administrator, but it still return “access to the path is denied”. My PowerShell is in Portuguese so maybe the translation of some items won’t be perfect.

      It worked for folders without folder inside (child?). If there’s a folder inside a folder, I get this error. If the folder has files but not other folders, it works fine.

    • #228310
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      but it still return “access to the path is denied”

      So you might have a problem with the given rights on the target folder. Most of the time when the message is “Access denied” you don’t have access. 😉 I just tested it and it worked just as expected. This is the before:

      … and this is the after:

    • #228319
      Participant
      Topics: 9
      Replies: 678
      Points: 2,683
      Helping Hand
      Rank: Community Hero

      It should rename the folders even if they have many descendants. Perhaps you don’t have permission to one of the sub folders/files or perhaps one of the paths exceeds 256 characters?

    • #228331
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Could you do just one more thing for me? It’s only to know what I do have to search for. Instead of this:

      Consider this one. Just another 2 folders inside one of the folders (my first example wasn’t clear because of the “- – -“). Inside “C:\São Paulo” there are 2 more folders named “Beach” and “Home”. It will be D:\Photos\2011\São Paulo\Home and D:\Photos\2011\São Paulo\Beach.

      It works fine for me if I don’t have these 2 folders inside “São Paulo”, but when I create them, it gives me this access error only for the folder with other folder inside. There are no files inside them. I used the tip these folder are only for test purposes.

      And… this limation of 256 characters is only for one level name, right? I mean, the whole path (“D:\Photo\Place\Location…”) can be more than 256, right?

    • #228364
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Before:

      After:

Viewing 6 reply threads
  • The topic ‘Rename-Item for not empty folders’ is closed to new replies.