30.06.2012 05:06
Canon EOS 500D, Canon EF 100mm f/2.8 L IS USM, clona 8, čas 1/250s, ISO 100, stativ
30.06.2012 05:06
Canon EOS 500D, Canon EF 100mm f/2.8 L IS USM, clona 8, čas 1/250s, ISO 100, stativ
Syntax:
Get-ChildItemPlus [-Path] <string> [-Level] <integer> [-Type] <string>
Example 1:
Get-ChildItemPlus c:\temp 2 Folder
This command retrieves all of the folders in the c:\temp path till second level.
Example 2:
Get-ChildItemPlus c:\temp 3 Files
This command retrieves all of the files in the c:\temp path till third level.
Parameters:
- Path
Specifies a path to location
- Level
Specifies a depth to search - e.g. c:\windows\system32 is level 2
- Type
The type of object that Get-ChildItem returns: File, Folder, Both
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Function Get-ChildItemPlus { Param ([Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 0)] [string]$Path = ".", [Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 1)] [int]$Level = 99, [Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 2)] [string]$Type = "") switch ($Type) { "Folder" {$Data = Get-ChildItem -Path "$Path" -Recurse | Where-Object {$_.psIsContainer -eq $True}} "File" {$Data = Get-ChildItem -Path "$Path" -Recurse | Where-Object {! $_.psIsContainer}} default {$Data = Get-ChildItem -Path "$Path" -Recurse} } if ($Data -eq $Null) {Break} $Level++ $Output = @() foreach ($Item in $Data) { $Folder = $Item.FullName.ToString() if ($Folder.Split("\").Count -le "$Level") { $Output += "$Folder" } } return $Output } |
It will change creation time of fileName.txt
|
1 |
Get-ChildItem "fileName.txt" | Foreach-Object { $_.CreationTime = '1/1/2020 12:34'} |
It will change values $TimeType of all files in $Folder
|
1 2 3 4 5 6 7 8 9 |
$Folder = Get-ChildItem "C:\temp\test\*" $FileTime = "3/10/1982 06:30" $TimeType = ("CreationTime", "LastWriteTime", "LastAccessTime") foreach ($File in $Folder) { foreach ($Time in $TimeType) { Get-ChildItem "$File" | Foreach-Object {$_."$Time" = "$FileTime"} } } |
It will change values $TimeSettings of all files in $Folder using Hash Table
|
1 2 3 4 5 6 7 8 9 10 |
$Folder = Get-ChildItem "C:\temp\test\*" $TimeSettings = @{'CreationTime' = '3/10/1975 06:30'; 'LastWriteTime' = '3/10/1982 06:30'; 'LastAccessTime' = '5/21/2012 13:30'} foreach ($File in $Folder) { $TimeSettings.GetEnumerator() | Foreach-Object { $FileProperty = $_.Key $DateValue = $_.Value Get-ChildItem "$File" | Foreach-Object {$_."$FileProperty" = "$DateValue"} } } |