Home > Enterprise >  how can ı do that moving subfolder to top folder
how can ı do that moving subfolder to top folder

Time:12-05

Can I do this with cmd?

for example

c:\a\a1\qw.exe => c:\a1\qw.exe like that

I have many directories like that so I want to learn how can I do this in windows?

I want to move many folders in one command

Thank you for your answer

CodePudding user response:

You can combine move with two for /d loops:

for /d %i in (?) do for /d %j in ("%i\*.*") do move "%j" .

The first loop will find all directories with a single character (? will match a, b) below the current directory. The second loop will find all directories (*.* will match everything) in these directories and move it to the current directory.

Replace ? by *.* if you don't have single letter directories. But be warned: do not run this in C:\, or it will attempt to move all folders out of the Windows and Program Files directory.

CodePudding user response:

The Move Command allows users to transfer files or directories from one directory to another, or from one drive to another.

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/move

move /?

Example of Move Command

To move the files of c:\windows\test to the test directory in the root directory, this is of course assuming you have the Windows\test directory.

move c:\windows\test\*.* c:\test

Powershell Move-Item

The Move-Item cmdlet moves an item, including its properties, contents, and child items, from one location to another location. The locations must be supported by the same provider. For example, it can move a file or subdirectory from one directory to another or move a registry subkey from one key to another. When you move an item, it is added to the new location and deleted from its original location.

https://social.technet.microsoft.com/Forums/en-US/729f90e2-4c1d-445d-ad72-6f752a3d7d24/powershell-move-folder-and-subfolders

Example Using PowerShell Move-Item

$parentpath = "C:\Temp"
$files = Get-ChildItem -Path $parentpath -Filter "*.txt" -Recurse
Set-Location $parentpath

New-Item -Name "test" -ItemType Directory -ErrorAction SilentlyContinue
Set-Location .\test

foreach ($file in $files)
{
   $destination = New-Item -ItemType directory -Name $(split-path $file.Directory -Leaf) -erroraction 'silentlycontinue'
   $file | Move-Item -Destination  $destination
}

Bit-Transfer

My Bit-Transfer script is here. I would place it here for you, but some start complaining that I copied my own script to this post.

backup www directory from local to network drive powershell

Here You Go Using WhatIf -- 'd:\deneme\a\a1', 'd:\deneme\b\b1', 'd:\deneme\c\c1' one level up 'd:\deneme\a1', 'd:\deneme\b1', 'd:\deneme\c1'

$paths = "d:\deneme\a\a1", "d:\deneme\b\b1", "d:\deneme\c\c1"

ForEach($path in $paths) {
    $path = $path.ToString()
    $up = $path.Substring(0, $path.lastIndexOf('\'))
    #Move-Item -Path $path -Destination $up -force -Verbose
    Move-Item -Path $path -Destination $up -WhatIf

}
  • Related