Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Locate Files & Export to Csv
- #region Function
- #region start
- $pathToScan = "E:\C00132 Seaford Head Golf Club" #Target path including subfolders and files
- $outputFilePath = "C:\Users\Jamie\Desktop\filelist.csv" #Directory must exist and not require admin rights
- $writeToConsoleAsWell = $true
- $outputFileDirectory = Split-Path $outputFilePath -Parent
- if (!(Test-Path $outputFileDirectory)) { New-Item $outputFileDirectory -ItemType Directory }
- $stream = New-Object System.IO.StreamWriter($outputFilePath, $false)
- Get-ChildItem -Path $pathToScan -Recurse -Force | `
- Select-Object -Property FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}} | `
- #endregion
- Sort-Object -Property FullNameLength -Descending | ForEach-Object {
- $filePath = $_.FullName
- $length = $_.FullNameLength
- $string = "$length : $filePath"
- if ($writeToConsoleAsWell) { Write-Host $string }
- $stream.WriteLine($string)
- }
- $stream.Close()
- #endregion
- #Find and replace characters
- #region begin
- #Import-Csv = "C:\Users\Jamie\Desktop\filelist.csv" | `
- #$dir = Set root path value
- $dir = "E:\"
- CD $dir
- Get-ChildItem -Recurse | `
- Where-Object { $_.Name -match 'FULL ADHERED REFURB DETAILS' } | `
- Rename-Item -NewName { $_.Name -replace 'FULL ADHERED REFURB DETAILS' , 'Fulladref' }
- Get-ChildItem -Recurse | `
- Where-Object { $_.Name -match 'C00132 Seaside Golf Club' } | `
- Rename-Item -NewName { $_.Name -replace 'C00132 Seaside Golf Club' , 'SSGC' }
- Get-ChildItem -Recurse | `
- Where-Object { $_.Name -match 'SS Information' } | `
- Rename-Item -NewName { $_.Name -replace 'SS Information' , 'SSInfo' }
- #endregion
- #Check to confirm amendment
- #region function
- #region begin
- $pathToScan = "C:\Users\Jamie\Desktop"
- $outputFilePath = "C:\Users\Jamie\Desktop\amendedfilelist.csv"
- $writeToConsoleAsWell = $true
- $outputFileDirectory = Split-Path $outputFilePath -Parent
- if (!(Test-Path $outputFileDirectory)) { New-Item $outputFileDirectory -ItemType Directory }
- $stream = New-Object System.IO.StreamWriter($outputFilePath, $false)
- Get-ChildItem -Path $pathToScan -Recurse -Force | `
- Select-Object -Property FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}} | `
- #endregion
- Sort-Object -Property FullNameLength -Descending | ForEach-Object {
- $filePath = $_.FullName
- $length = $_.FullNameLength
- $string = "$length : $filePath"
- if ($writeToConsoleAsWell) { Write-Host $string }
- $stream.WriteLine($string)
- }
- $stream.Close()
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement