Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6811161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:17:36+00:00 2026-05-26T20:17:36+00:00

I have created a gui with powershell that allows me to copy files from

  • 0

I have created a gui with powershell that allows me to copy files from inside folders into one place .

Example you have a folder A and in folder A there is Folder B and C inside all these folders you have a bunch of logfiles named logfile + date.log

My app can hunt through all the folders and move copy the log files to a single location.

The script works but when it is getting a list of files to copy it is slow and says “Not responding” at the top of the window next to where it says “Copy Files To One Directory”

I have added the script can you guys have a look and let me know how to speed it up.
The functions it hik are causing the problem are after the “These are the function I seems to be having a problem with”

Thank for the help.
The code

    #------------------------------------------------------------------------
    # Source File Information (DO NOT MODIFY)
    # Source ID: 3020bcd1-4cba-4aca-968e-b4bc4ca05d76
    # Source File: Copy\Copy.pfproj
    #------------------------------------------------------------------------
    #========================================================================
    # Generated On: 11/15/2011 5:11 PM
    # Generated By: justin
    #========================================================================

#---------------------------------------------- #region Import Assemblies #---------------------------------------------- [void][Reflection.Assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") [void][Reflection.Assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][Reflection.Assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") #endregion Import Assemblies #Define a Param block to use custom parameters in the project #Param ($CustomParameter) function Main { Param ([String]$Commandline) #Note: This function starts the application #Note: $Commandline contains the complete argument string passed to the packager #Note: $Args contains the parsed arguments passed to the packager (Type: System.Array) #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path #Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList) #TODO: Initialize and add Function calls to forms if((Call-MainForm_pff) -eq "OK") { } $global:ExitCode = 0 #Set the exit code for the Packager } #region Call-MainForm_pff function Call-MainForm_pff { #---------------------------------------------- #region Import the Assemblies #---------------------------------------------- [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") #endregion Import Assemblies #---------------------------------------------- #region Generated Form Objects #---------------------------------------------- [System.Windows.Forms.Application]::EnableVisualStyles() $CopyFilesToOneDirectoy = New-Object System.Windows.Forms.Form $labelExtension = New-Object System.Windows.Forms.Label $labelFileName = New-Object System.Windows.Forms.Label $Extension = New-Object System.Windows.Forms.TextBox $FileName = New-Object System.Windows.Forms.TextBox $buttonSetDestination = New-Object System.Windows.Forms.Button $buttonSetSource = New-Object System.Windows.Forms.Button $Dlabel = New-Object System.Windows.Forms.Label $Slabel = New-Object System.Windows.Forms.Label $DestinationFolder = New-Object System.Windows.Forms.TextBox $SourceFolder = New-Object System.Windows.Forms.TextBox $progress = New-Object System.Windows.Forms.ProgressBar $buttonCopyFiles = New-Object System.Windows.Forms.Button $sourcebrowserdialog = New-Object System.Windows.Forms.FolderBrowserDialog $destinationbrowserdialog = New-Object System.Windows.Forms.FolderBrowserDialog $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- # User Generated Script #---------------------------------------------- $OnLoadFormEvent={ } $buttonSetSource_Click={ $result = $sourcebrowserdialog.ShowDialog() if ($result -eq 'Ok'){ $SourceFolder.Text =$sourcebrowserdialog.SelectedPath } else{ $SourceFolder.Text = '' } } $buttonSetDestination_Click={ $result = $destinationbrowserdialog.ShowDialog() if ($result -eq 'Ok'){ $DestinationFolder.Text =$destinationbrowserdialog.SelectedPath } else{ $DestinationFolder.Text = '' } } $buttonCopyFiles_Click={ #TODO: Place custom script here $progress.Value = 0 $CName = $FileName.Text $CExtension = "." + $Extension.Text $CSource = $SourceFolder.Text $CDestination = $DestinationFolder.Text CopyfFiles $CSource $CDestination $CName $CExtension } # --End User Generated Script-- #---------------------------------------------- #region Generated Events #---------------------------------------------- $Form_StateCorrection_Load= { #Correct the initial state of the form to prevent the .Net maximized form issue $CopyFilesToOneDirectoy.WindowState = $InitialFormWindowState } $Form_StoreValues_Closing= { #Store the control values $script:MainForm_Extension = $Extension.Text $script:MainForm_FileName = $FileName.Text $script:MainForm_DestinationFolder = $DestinationFolder.Text $script:MainForm_SourceFolder = $SourceFolder.Text } $Form_Cleanup_FormClosed= { #Remove all event handlers from the controls try { $buttonSetDestination.remove_Click($buttonSetDestination_Click) $buttonSetSource.remove_Click($buttonSetSource_Click) $buttonCopyFiles.remove_Click($buttonCopyFiles_Click) $CopyFilesToOneDirectoy.remove_Load($OnLoadFormEvent) $CopyFilesToOneDirectoy.remove_Load($Form_StateCorrection_Load) $CopyFilesToOneDirectoy.remove_Closing($Form_StoreValues_Closing) $CopyFilesToOneDirectoy.remove_FormClosed($Form_Cleanup_FormClosed) } catch [Exception] { } } #endregion Generated Events #---------------------------------------------- #region Generated Form Code #---------------------------------------------- # # CopyFilesToOneDirectoy # $CopyFilesToOneDirectoy.Controls.Add($labelExtension) $CopyFilesToOneDirectoy.Controls.Add($labelFileName) $CopyFilesToOneDirectoy.Controls.Add($Extension) $CopyFilesToOneDirectoy.Controls.Add($FileName) $CopyFilesToOneDirectoy.Controls.Add($buttonSetDestination) $CopyFilesToOneDirectoy.Controls.Add($buttonSetSource) $CopyFilesToOneDirectoy.Controls.Add($Dlabel) $CopyFilesToOneDirectoy.Controls.Add($Slabel) $CopyFilesToOneDirectoy.Controls.Add($DestinationFolder) $CopyFilesToOneDirectoy.Controls.Add($SourceFolder) $CopyFilesToOneDirectoy.Controls.Add($progress) $CopyFilesToOneDirectoy.Controls.Add($buttonCopyFiles) $CopyFilesToOneDirectoy.ClientSize = '458, 245' $CopyFilesToOneDirectoy.Name = "CopyFilesToOneDirectoy" $CopyFilesToOneDirectoy.StartPosition = 'CenterScreen' $CopyFilesToOneDirectoy.Text = "Copy Files To One Directoy" $CopyFilesToOneDirectoy.add_Load($OnLoadFormEvent) # # labelExtension # $labelExtension.AutoSize = $True $labelExtension.Font = "Microsoft Sans Serif, 9.75pt, style=Bold" $labelExtension.Location = '349, 54' $labelExtension.Name = "labelExtension" $labelExtension.Size = '75, 16' $labelExtension.TabIndex = 11 $labelExtension.Text = "Extension" # # labelFileName # $labelFileName.AutoSize = $True $labelFileName.Font = "Microsoft Sans Serif, 9.75pt, style=Bold" $labelFileName.Location = '12, 54' $labelFileName.Name = "labelFileName" $labelFileName.Size = '79, 16' $labelFileName.TabIndex = 10 $labelFileName.Text = "File Name" # # Extension # $Extension.Font = "Microsoft Sans Serif, 9.75pt" $Extension.Location = '349, 74' $Extension.Name = "Extension" $Extension.Size = '93, 22' $Extension.TabIndex = 9 # # FileName # $FileName.Font = "Microsoft Sans Serif, 9.75pt" $FileName.Location = '12, 74' $FileName.Name = "FileName" $FileName.Size = '300, 22' $FileName.TabIndex = 8 # # buttonSetDestination # $buttonSetDestination.Location = '349, 173' $buttonSetDestination.Name = "buttonSetDestination" $buttonSetDestination.Size = '93, 23' $buttonSetDestination.TabIndex = 7 $buttonSetDestination.Text = "Set Destination" $buttonSetDestination.TextAlign = 'MiddleLeft' $buttonSetDestination.UseVisualStyleBackColor = $True $buttonSetDestination.add_Click($buttonSetDestination_Click) # # buttonSetSource # $buttonSetSource.Location = '349, 123' $buttonSetSource.Name = "buttonSetSource" $buttonSetSource.Size = '93, 23' $buttonSetSource.TabIndex = 6 $buttonSetSource.Text = "Set Source" $buttonSetSource.UseVisualStyleBackColor = $True $buttonSetSource.add_Click($buttonSetSource_Click) # # Dlabel # $Dlabel.AutoSize = $True $Dlabel.Font = "Microsoft Sans Serif, 9.75pt, style=Bold" $Dlabel.Location = '12, 154' $Dlabel.Name = "Dlabel" $Dlabel.Size = '135, 16' $Dlabel.TabIndex = 5 $Dlabel.Text = "Destination Folder" # # Slabel # $Slabel.AutoSize = $True $Slabel.Font = "Microsoft Sans Serif, 9.75pt, style=Bold" $Slabel.Location = '12, 104' $Slabel.Name = "Slabel" $Slabel.Size = '106, 16' $Slabel.TabIndex = 4 $Slabel.Text = "Source Folder" # # DestinationFolder # $DestinationFolder.Font = "Microsoft Sans Serif, 9.75pt" $DestinationFolder.Location = '12, 174' $DestinationFolder.Name = "DestinationFolder" $DestinationFolder.Size = '300, 22' $DestinationFolder.TabIndex = 3 $DestinationFolder.Text = "c:\td" # # SourceFolder # $SourceFolder.Font = "Microsoft Sans Serif, 9.75pt" $SourceFolder.Location = '12, 124' $SourceFolder.Name = "SourceFolder" $SourceFolder.Size = '300, 22' $SourceFolder.TabIndex = 2 $SourceFolder.Text = "c:\ts" # # progress # $progress.Location = '12, 212' $progress.Name = "progress" $progress.Size = '300, 23' $progress.TabIndex = 1 # # buttonCopyFiles # $buttonCopyFiles.Location = '349, 212' $buttonCopyFiles.Name = "buttonCopyFiles" $buttonCopyFiles.Size = '93, 23' $buttonCopyFiles.TabIndex = 0 $buttonCopyFiles.Text = "Copy Files" $buttonCopyFiles.UseVisualStyleBackColor = $True $buttonCopyFiles.add_Click($buttonCopyFiles_Click) # # sourcebrowserdialog # $sourcebrowserdialog.RootFolder = 'MyComputer' $sourcebrowserdialog.ShowNewFolderButton = $False # # destinationbrowserdialog # $destinationbrowserdialog.RootFolder = 'MyComputer' $destinationbrowserdialog.ShowNewFolderButton = $False #endregion Generated Form Code #---------------------------------------------- #Save the initial state of the form $InitialFormWindowState = $CopyFilesToOneDirectoy.WindowState #Init the OnLoad event to correct the initial state of the form $CopyFilesToOneDirectoy.add_Load($Form_StateCorrection_Load) #Clean up the control events $CopyFilesToOneDirectoy.add_FormClosed($Form_Cleanup_FormClosed) #Store the control values when form is closing $CopyFilesToOneDirectoy.add_Closing($Form_StoreValues_Closing) #Show the Form return $CopyFilesToOneDirectoy.ShowDialog() } #endregion #-------------------------------------------------------------------------------------------------------------------------------------------------- # These are the function I seems to be havig a problem with #Sample function that provides the location of the script function Get-ScriptDirectory { if($hostinvocation -ne $null) { Split-Path $hostinvocation.MyCommand.path } else { Split-Path $script:MyInvocation.MyCommand.Path } } function ListOfFiles ($Source,$Name,$Extension){ $FileListArray = @() foreach($file in Get-ChildItem $Source -Force -Recurse | Where-Object {$_.name -like $Name -and $_.Extension -eq $Extension}) { If ($FileListArray -match "$file") { $NewFileName = $file.Directory.Name + "." + $file.Name $FileListArray += ,@($file,$file.FullName,$NewFileName) } Else { $FileListArray += ,@($file,$file.FullName,$file) } } Return $FileListArray } Function CopyfFiles ($Source,$Destination,$Name,$Extension){ $ListFiles = @(listOfFiles -Source $Source -Name $Name -Extension $Extension) $ListFilesTemp = @() Foreach ($CF in $ListFiles) { $Check = $Destination + "\"+ $CF[2] #If The File is Not Already In The Destination Add It To The Temp Array IF (Test-Path -Path "$Check") {} Else {$ListFilesTemp += ,@($CF[0],$CF[1],$CF[2])} $ListFiles = $ListFilesTemp } $progress.Minimum = 0 $progress.Maximum = $ListFiles.Count $progress.Step = 1 Foreach ($File in $ListFiles) { $FileDestination = $Destination + "\"+ $File[2] Copy-Item -Path $File[1] -Destination $FileDestination $progress.PerformStep() } } #Sample variable that provides the location of the script [string]$ScriptDirectory = Get-ScriptDirectory #-------------------------------------------------------------------------------------------------------------------------------------------------- #endregion #Start the application Main ($CommandLine) <code>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:17:37+00:00Added an answer on May 26, 2026 at 8:17 pm

    “Not Responding” means the thread isn’t waiting for windowing input (in your example the thread is running the powershell code). I don’t think there is a trivial way to create new threads in Powershell. However, you might be able to make your GUI more responsive using PowerBoots and powershell jobs like in this example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a PHP-script to update a web server that is live inside
I have created a GUI which requires .dll files in order to work. Here
Say I have created a GUI (Qt) that operates with some data(text+image). How I
I have created one GUI using Swing of Java. I have to now set
I have created a GUI program that uses a class to perform some tasks.
I have created a program in c++ that doesn't have any GUI. When this
I have created one GUI in which I have used a JFrame. How should
I have created a fairly substantial Java GUI application with many form windows where
I am using swing to create my GUI. J have a JFrame containing one
I have a class (simulation) which creates an instance of another class (GUI). Inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.