Laslos
Laslos

Reputation: 360

Copy selected files to another folder using powershell

I am trying to accomplish the following:

  1. Open a Windows File Explorer and navigate to a particular folder.
  2. Select certain files and/or folders within that folder using the mouse.
  3. Write a powershell script that detects the files/folders I have selected, and copies to another location.

What I need to know, is there a way for powershell to detect the files I have selected in the File Explorer? I have tried to locate resources online to give me some insight, but no luck, either it isn't possible or I am searching the wrong terminology.

Upvotes: 1

Views: 2424

Answers (3)

Esperento57
Esperento57

Reputation: 17472

Or without explorer (then you can navigate, but if you know your directory its an other method) :

Get-ChildItem "c:\temp" -file | 
    Out-GridView -Title "Select your files" -OutputMode Multiple | 
        Copy-Item -Destination "C:\tempdest"

Upvotes: 1

Esperento57
Esperento57

Reputation: 17472

Something like this (keep CTRL key pressed and select your files)

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = "c:\temp"
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.Multiselect=$true
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.FileNames | Copy-Item -Destination "C:\tempdest"
$OpenFileDialog.Dispose()

Upvotes: 1

vrdse
vrdse

Reputation: 3154

Most likely it makes more sense to use an OpenFileDialog.

Upvotes: 1

Related Questions