Powershell: How do i get the basename of an element of an array and compare if there is a file with the same basename in the directory
#*******************************************************************
#Auteur: Casper Limburg
#*******************************************************************
cls
#*******************************************************************
# Declare variable & constrains 
#*******************************************************************

$DirVan = "C:\BestandVerplaatsen\van\*"
$DirNa = "C:\BestandVerplaatsen\naar" 
#$File = Get-ChildItem C:\BestandVerplaatsen\van\*.* # HELP !! --> this is still an object wich contains an array
#I need an object wich contains an item of that array because i need to compare it later with an array i can't compare it
#or i don't know how           
$File = ??? #HELP how to get an object wich contains one item of the array

echo "print sfile"
$File
echo ""

#*******************************************************************
# Report baseName's
#*******************************************************************
#echo "basename wordt geplrint"
echo "print basename of all files"

#get basename all files
$a = gci C:\BestandVerplaatsen\van\* | % {$_.BaseName}     #$FilenameProper=$_.BaseName 
$a 


#echo whiteline
echo ""

#get basename xml files
echo "print basename of .xml files"
$b = gci C:\BestandVerplaatsen\van\* -filter '*.xml' | % {$_.BaseName}
$b



#*******************************************************************
# if files in directory copy to specific place
#*******************************************************************
foreach ($File in $DirVan){
    $exists = $DirVan | Where-Object {$_.BaseName -eq $_.BaseName}  # Help !!!
    #what to fill in here because it needs to compare if there is a file in de directory with the same basename. 
    # if there is another file with the same basename it should execute some code below 
    if($exists) 
    {
    # execute code 
    }
  }

June 18th, 2015 5:19am

btw i'm new with powershell i prorgam c# for some time just for fun but now i have to make this script for my work
Free Windows Admin Tool Kit Click here and download it now
June 18th, 2015 7:38am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics