Forum Discussion

Kenneth Green's avatar
Kenneth Green
Brass Contributor
Mar 02, 2024
Solved

Powershell script move contents of child folder to parent, go to next folder and repeat

Windows 10 I am not very literate in powershell script but I trying to create a Power Shell script that does the following.   For this example I am using "C:\Test" as a testing folder and the file...
  • LainRobertson's avatar
    LainRobertson
    Mar 08, 2024

    I've reproduced the "process lock" scenario you've run into, and the outcome matches expectations on my side - keeping in mind none of this requires administrative access (I'm always operating as an unprivileged user in accordance with best practice).

     

    In the output example below, we see the "before" and "after" file layout, where I've deliberately locked the following path by virtue of changing the command prompt session to using it:

     

    D:\Data\Temp\Forum\Root\Parent1\Child1

     

    As a result, when I've then run the script, this path failed to be moved, hence the two files it contains remain in their original location - nothing was deleted.

     

    Because this specific version of "Child1" failed, it allowed the next iteration of "Child1" - located under Parent2 - to succeed in moving - all of which can be seen in the "after" directory listing.

     

    The key takeaway though is that nothing was deleted, so if you're seeing that, then I'm unsure how that's come about.

     

    Output

     

     

    Cheers,

    Lain

Resources