PowerShell: Failide sorteerimine laiendi järgi: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Iromanen (talk | contribs)
No edit summary
Iromanen (talk | contribs)
No edit summary
Line 23: Line 23:


#>
#>
# Autor: Inger Romanenko


# Versioon 1.0


echo "Skript k2ivitus"
echo "Skript k2ivitus"

Revision as of 21:56, 14 May 2012

<Source lang="powershell">

<#

.SYNOPSIS Skript küsib 2 parameetrit: kaust kust otsitakse ja uus kaust. Käib läbi kõik failid otsingu kaustast (ja alamkaustadest). Loob uue kausta ja sellesse leitud laiendite nimelised alamkaustad ja kopeerib failid vastavalt laiendile kaustadesse.

.DESCRIPTION Sisesta kaks parameetrit: kaust, kust otsitakse ja uus kaust, kuhu failid kopeeritakse

.Example

 C:\Documents .\powershell_inger.ps1 minukaust uuskaust

.NOTES

 Autor: Inger Romanenko
 Versioon: 0.1
 Muutmise kuup2ev 14.05.2012

.LINK

 https://wiki.itcollege.ee/index.php/PowerShell:_Failide_sorteerimine_laiendi_j%C3%A4rgi


  1. >


echo "Skript k2ivitus" $otsing = $args[0] $uus = $args[1]

$usage = "Sisesta kaks parameetrit: kaust, kust otsitakse ja uus kaust, kuhu failid kopeeritakse" $usage2 = "Sellist kausta pole"

if ($args.Count -ne 2) {

   echo $usage
   exit

}

if (!(Test-Path $otsing -ErrorVariable SilentlyContinue)){

   echo $usage2
   exit

}

if (!(Test-Path $uus)) {

       New-Item $uus.ToString() -type directory | out-null
       }

$files = gci $otsing -rec | where { ! $_.PSIsContainer } $files | % {

       $type = $_.extension
       $fname = $_.fullname
       $dir = $type.Substring(1)
       $path = Join-Path $uus $dir
       if (!(Test-Path $path)) {
       New-Item $path.ToString() -type directory | out-null
       }
       Copy-Item $_.fullname $path -ErrorAction SilentlyContinue

}