mirror of
https://github.com/serialexperiments0815/PowershellExcercises.git
synced 2026-07-12 15:32:25 +00:00
Corrected many "./" path entries to $($PSScriptRoot).
This commit is contained in:
parent
0e1b23f888
commit
9dc9824b12
9 changed files with 17 additions and 17 deletions
|
|
@ -4,4 +4,4 @@
|
|||
# '-File' returns results for files only, no directories.
|
||||
# '-Filter' returns results for specified string pattern.
|
||||
|
||||
Get-ChildItem -Path "./" -Recurse -File -Filter *.ps1
|
||||
Get-ChildItem -Path "$($PSScriptRoot)" -Recurse -File -Filter *.ps1
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
# '-Recurse' instructs iterations through subdirectories.
|
||||
# '-File' returns results for files only, no directories.
|
||||
|
||||
Get-ChildItem -Path './' -Recurse -File |
|
||||
Get-ChildItem -Path "$($PSScriptRoot)" -Recurse -File |
|
||||
|
||||
# Call 'Select-Object' cmdlet method to return specified properties.
|
||||
# '-Property FullName' returns full String path for each object.
|
||||
|
|
@ -15,4 +15,4 @@ Get-ChildItem -Path './' -Recurse -File |
|
|||
# '-Path './folderFiles.csv'' returns output of file in current directory.
|
||||
# '-NoTypeInformation' supresses #TYPE metadata line.
|
||||
|
||||
Export-Csv -Path './folderFiles.csv' -NoTypeInformation
|
||||
Export-Csv -Path "$($PSScriptRoot)/folderFiles.csv" -NoTypeInformation
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
# "./" In current directory.
|
||||
# "-Filter *.PNG" Of the type PNG.
|
||||
|
||||
Get-ChildItem "./" -Filter *.PNG |
|
||||
Get-ChildItem "$($PSScriptRoot)" -Filter *.PNG |
|
||||
|
||||
# Calling 'ForEach-Object' loop method for iterating through returned files.
|
||||
ForEach-Object {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
# (Get-Item $file).LastWriteTime = $oldDate
|
||||
# (Get-Item $file).LastAccessTime = $oldDate
|
||||
|
||||
Get-ChildItem ".\" -Recurse |
|
||||
Get-ChildItem "$($PSScriptRoot)" -Recurse |
|
||||
Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} |
|
||||
Remove-Item -Force -WhatIf
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Export all file and folder path to folderFileList.csv
|
||||
# Select-Object FullName property was chosen to only export the full path.
|
||||
Get-ChildItem -Path "./" -Recurse |
|
||||
Get-ChildItem -Path "$($PSScriptRoot)" -Recurse |
|
||||
Select-Object -Property FullName |
|
||||
Export-Csv -Path "./folderFileList.csv" -NoTypeInformation
|
||||
Export-Csv -Path "$($PSScriptRoot)/folderFileList.csv" -NoTypeInformation
|
||||
|
|
@ -5,21 +5,21 @@
|
|||
[String[]]$pictureFormat = "jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "webp", "heic", "heif", "raw", "cr2", "nef", "arw", "svg", "ico"
|
||||
[String[]]$documentFormat = "pdf", "doc", "docx", "odt", "rtf", "txt", "csv", "xls", "xlsx", "ods", "ppt", "pptx", "odp", "md", "html", "xml"
|
||||
|
||||
$filesInFolder = Get-ChildItem -Path "./" -File
|
||||
$filesInFolder = Get-ChildItem -Path "$($PSScriptRoot)" -File
|
||||
|
||||
foreach($file in $filesInFolder){
|
||||
$extension = $file.Extension.TrimStart('.').ToLower()
|
||||
|
||||
if ($videoFormat -contains $extension){
|
||||
Move-Item -Path $file.FullName -Destination "./videos/$($file.Name)"
|
||||
Move-Item -Path $file.FullName -Destination "$($PSScriptRoot)/videos/$($file.Name)"
|
||||
}
|
||||
|
||||
elseif ($pictureFormat -contains $extension) {
|
||||
Move-Item -Path $file.FullName -Destination "./pictures/$($file.Name)"
|
||||
Move-Item -Path $file.FullName -Destination "$($PSScriptRoot)/pictures/$($file.Name)"
|
||||
}
|
||||
|
||||
elseif ($documentFormat -contains $extension) {
|
||||
Move-Item -Path $file.FullName -Destination "./documents/$($file.Name)"
|
||||
Move-Item -Path $file.FullName -Destination "$($PSScriptRoot)/documents/$($file.Name)"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# File searches for txt files and replaces specified string.
|
||||
|
||||
$textFiles = Get-ChildItem -Path "./" -Filter *.txt
|
||||
$textFiles = Get-ChildItem -Path "$($PSScriptRoot)" -Filter *.txt
|
||||
$searchText = 'this text is false'
|
||||
$replaceText = 'this text is true'
|
||||
foreach($textFile in $textFiles){
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
# As the -Filter parameter only matches folders at current level, not recursively in all subfolders.
|
||||
|
||||
$nameOfFolder = "important"
|
||||
$directionOfFolder = Get-ChildItem -Path "./" -Recurse -Directory | Where-Object { $_.Name -eq $nameOfFolder }
|
||||
Copy-Item -Path $directionOfFolder.FullName -Destination (Join-Path "./safe/" $directionOfFolder.Name) -Recurse -Force
|
||||
$directionOfFolder = Get-ChildItem -Path "$($PSScriptRoot)" -Recurse -Directory | Where-Object { $_.Name -eq $nameOfFolder }
|
||||
Copy-Item -Path $directionOfFolder.FullName -Destination (Join-Path "$($PSScriptRoot)/safe/" $directionOfFolder.Name) -Recurse -Force
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
# Test-Path added to avoid Remove-Item error on first execution.
|
||||
# Remove-Item was added to avoid complications with Export-Csv function.
|
||||
# Delimiter was added to not have all properties stacked in the same column.
|
||||
if (Test-Path "./InstalledPrograms.csv"){
|
||||
Remove-Item -Path "./InstalledPrograms.csv"
|
||||
if (Test-Path "$($PSScriptRoot)/InstalledPrograms.csv"){
|
||||
Remove-Item -Path "$($PSScriptRoot)/InstalledPrograms.csv"
|
||||
}
|
||||
Get-Package | Select-Object -Property Name, Version, Summary |
|
||||
Export-Csv -Path "./InstalledPrograms.csv" -NoTypeInformation -Delimiter ";"
|
||||
Export-Csv -Path "$($PSScriptRoot)/InstalledPrograms.csv" -NoTypeInformation -Delimiter ";"
|
||||
|
|
|
|||
Loading…
Reference in a new issue