Jump to content

copy a folder with Shell.Application


Recommended Posts

I have a folder A   (  C:\FolderA  ),  It contains many files :

C:\FolderA\1.jpg

C:\FolderA\2.jpg

C:\FolderA\3.jpg

...

I want to copy the folder A to the folder B   (  C:\FolderB  ) like follow :

C:\FolderB\1.jpg

C:\FolderB\2.jpg

C:\FolderB\3.jpg

...

 

I do not want to use  'DirCopy',although this code can  help me achieve my request:

$SourceDir = 'C:\FolderA'
$Destdir = 'C:\FolderB'
DirCopy($SourceDir,$Destdir,1)

 

I want to use 'Shell.Application ' instand  ,so this is my code as follow:

$SourceDir = 'C:\FolderA'
$Destdir = 'C:\FolderB'
$Shell = ObjCreate("Shell.Application")
$Shell.NameSpace($Destdir).MoveHere($SourceDir, 16)

 

My problem is :

when i use 'Shell.Application '  ,  The folder B turns this way:

C:\FolderB\FolderA\1.jpg

C:\FolderB\FolderA\2.jpg

C:\FolderB\FolderA\3.jpg

...

 

what i need is:

C:\FolderB\1.jpg  

C:\FolderB\2.jpg 

C:\FolderB\3.jpg 

...

so can you help me ?

Link to comment
Share on other sites

you're lucky today...

$objShell = ObjCreate("Shell.Application")
$SourceDir = $objShell.NameSpace('C:\Users\root\Desktop\FolderA')
$Destdir = $objShell.NameSpace('C:\Users\root\Desktop\FolderB')

$item = $SourceDir.Items

ConsoleWrite("Tot file "&$item.Count)

For $x = 0 to $item.Count -1
    ConsoleWrite($item.Item($x).Name&@CRLF)
    $Destdir.MoveHere($item.Item($x).Name)
Next

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...