• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What PS move-item script to move files and NOT flatten directory structure?

Doppel

Lifer
I have this folder structure with various files within various levels:

LEV1
LEV1\LEV2
LEV1\LEV2\FOLDER A
LEV1\LEV2\FOLDER B
..etc.

Also a destination folder DESTLEV1

A simple move-item will move these files but flattens the structure. It's necessary to maintain it, so that every time I run it I move folders and files, maintaining their order--anything from LEV1.

I can't find a good example online that actually works. Thanks for any ideas 🙂
 
Maybe I don't understand what you're trying to accomplish, but I used move-item and it did what you seem to want to do.

Code:
move-item -path c:\LEV1 -destination d:\DESTLEV1

resulted in
Code:
d:\DESTLEV1\LEV1\
d:\DESTLEV1\LEV1\FOLDER A
d:\DESTLEV1\LEV1\FOLDER A\file.txt
d:\DESTLEV1\LEV1\FOLDER B
...
 
Thanks, merlin, and you do understand. In fact, what you write works as I asked, which was my bad.

To my amazement, although your script works to move the LEV1 and all its folders into DESTLEV1, what doesn't work is if instead of LEV1 I want to move LEV2 (and in fact that is the case).

If I only want to move LEV2 and its subfolders and files and leave LEV1 where it is I get

"Access to the path 'c:\LEV1\LEV2' is denied

SO I can move LEV1 and its contents, but not if I get a little more narrow and only LEV2 and its contents.
 
Does this "PS" (I assume it is not PostScript?) have a concept of "current working directory"? If yes, then is should probably support relative paths as well:
Code:
cd c:\LEV1
move-item -path LEV2 ...
 
Hi mv2devnull, I meant PowerShell. I don't believe it has the concept of a current working directory. At least for the move-item command it doesn't...
 
Your access denied error is probably not related to the move-item command and more to do with your environment.

Try running the powershell script as Administrator you're running the script directly, or if you're running from a command prompt make sure that the command prompt is running as administrator before you launch powershell to run the script.
 
Your access denied error is probably not related to the move-item command and more to do with your environment.

Try running the powershell script as Administrator you're running the script directly, or if you're running from a command prompt make sure that the command prompt is running as administrator before you launch powershell to run the script.
I tried that 🙁I can run it with c:\LEV1 and no issue and immediately after if I try c:\LEV1\LEV2 it fails me out.

EDIT: Agh, it's an annoying permissions thing. I just ran it with the c:\lev1\lev2 and it worked fine, then ran it again with that directory open in windows explorer and it failed; guessing the OS still thinks some other process has that folder...Yep, this is it, I need to close out explorer for it to totally release that folder.

Thanks for the help!
 
Last edited:
I tried that 🙁I can run it with c:\LEV1 and no issue and immediately after if I try c:\LEV1\LEV2 it fails me out.

EDIT: Agh, it's an annoying permissions thing. I just ran it with the c:\lev1\lev2 and it worked fine, then ran it again with that directory open in windows explorer and it failed; guessing the OS still thinks some other process has that folder...Yep, this is it, I need to close out explorer for it to totally release that folder.

Thanks for the help!

Yeah, Explorer can be a real pain in the ass in that regard.
 
Back
Top