1

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.

7
  • 2
    Why would you accomplish this? Most likely it makes more sense to use an OpenFileDialog. Commented Feb 26, 2018 at 18:20
  • I am working on a large website not under version control, trying to write this script to copy certain files and/or folders I have made changes to, to another folder to diff the test site with the live site - could be anywhere from a few files to a few hundred. Currently I am manually copying and pasting these into a separate folder to diff them, looking for a way to automate the process. Commented Feb 26, 2018 at 18:27
  • I will try the OpenFileDialog - seems like it may meet my needs. Commented Feb 26, 2018 at 18:35
  • 1
    I also think that the OpenFileDialog control (which you can use in powershell) is probably the best bet. Having said that you can use it with Out-Gridview also. Commented Feb 26, 2018 at 18:35
  • 1
    You may want to look at this answer: stackoverflow.com/questions/15932881/… Commented Feb 26, 2018 at 18:42

3 Answers 3

1

Most likely it makes more sense to use an OpenFileDialog.

Sign up to request clarification or add additional context in comments.

Comments

1

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()

Comments

1

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.