mirror of
https://github.com/serialexperiments0815/PowershellExcercises.git
synced 2026-11-07 12:55:30 +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
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue