Powershell Basic

This topic contains 2 replies, has 2 voices, and was last updated by  Albert van Boerum 6 months, 3 weeks ago.

  • Author
    Posts
  • #65538

    Hey,
    i want to copy a file in specific folders
    the folder name can chance due to different versions of the software.
    org.xmind.ui.resources_*VERSION*
    org.xmind.ui.resources_3.7.0.201612151837

    in every of this Folders org.xmind.ui.resources_*
    i want my file to be copied.
    Ist there an easy way to make this possible
    Thanks in advance.

  • #65553

    basically i want him to check if there is folders with this name and then copy my file into them
    but not only into them
    my file need to be in a subfolder
    org.xmind.ui.resources_3.7.0.201612151837\templates\myfile

    so powershell should check for folders with that name to then copy my file into the template subfolder of those he found.

  • #65562

    Albert van Boerum
    Participant

    Hi,

    You can use this script to check the folder and overwrite the existing file if present.

    $sourcefile = 'c:\test\file.txt'
    $destinationroot = Get-ChildItem -Path c:\org.xmind.ui.resources_* -Directory
    
    If (Test-Path -Path $destinationroot) 
    {
    	$destinationfolder = "$destinationroot\templates\myfile"
    
    	Copy-Item -Path $sourcefile -Destination $destinationfolder -Force
    }
    
    

    good luck,
    Albert

You must be logged in to reply to this topic.