Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Locate Files & Export to Csv
  2. #region Function
  3. #region start
  4. $pathToScan = "E:\C00132 Seaford Head Golf Club"  #Target path including subfolders and files
  5. $outputFilePath = "C:\Users\Jamie\Desktop\filelist.csv" #Directory must exist and not require admin rights
  6.  
  7. $writeToConsoleAsWell = $true
  8. $outputFileDirectory = Split-Path $outputFilePath -Parent
  9.  
  10. if (!(Test-Path $outputFileDirectory)) { New-Item $outputFileDirectory -ItemType Directory }
  11. $stream = New-Object System.IO.StreamWriter($outputFilePath, $false)
  12.  
  13. Get-ChildItem -Path $pathToScan -Recurse -Force | `
  14. Select-Object -Property FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}} | `
  15. #endregion
  16.  
  17. Sort-Object -Property FullNameLength -Descending | ForEach-Object {
  18.     $filePath = $_.FullName
  19.     $length = $_.FullNameLength
  20.     $string = "$length : $filePath"
  21.    
  22.     if ($writeToConsoleAsWell) { Write-Host $string }
  23.     $stream.WriteLine($string)
  24. }
  25. $stream.Close()
  26. #endregion
  27.  
  28. #Find and replace characters
  29. #region begin
  30. #Import-Csv  = "C:\Users\Jamie\Desktop\filelist.csv" | `
  31. #$dir = Set root path value
  32. $dir = "E:\"
  33. CD $dir
  34. Get-ChildItem -Recurse | `
  35. Where-Object { $_.Name -match 'FULL ADHERED REFURB DETAILS' } | `
  36. Rename-Item -NewName  {  $_.Name -replace 'FULL ADHERED REFURB DETAILS' , 'Fulladref'  }
  37. Get-ChildItem -Recurse | `
  38. Where-Object { $_.Name -match 'C00132 Seaside Golf Club' } | `
  39. Rename-Item -NewName  {  $_.Name -replace 'C00132 Seaside Golf Club' , 'SSGC'  }
  40. Get-ChildItem -Recurse | `
  41. Where-Object { $_.Name -match 'SS Information' } | `
  42. Rename-Item -NewName  {  $_.Name -replace 'SS Information' , 'SSInfo'  }
  43. #endregion
  44.  
  45. #Check to confirm amendment
  46. #region function
  47. #region begin
  48. $pathToScan = "C:\Users\Jamie\Desktop"
  49. $outputFilePath = "C:\Users\Jamie\Desktop\amendedfilelist.csv"
  50. $writeToConsoleAsWell = $true
  51. $outputFileDirectory = Split-Path $outputFilePath -Parent
  52. if (!(Test-Path $outputFileDirectory)) { New-Item $outputFileDirectory -ItemType Directory }
  53. $stream = New-Object System.IO.StreamWriter($outputFilePath, $false)
  54.  
  55. Get-ChildItem -Path $pathToScan -Recurse -Force | `
  56. Select-Object -Property FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}} | `
  57. #endregion
  58.  
  59. Sort-Object -Property FullNameLength -Descending | ForEach-Object {
  60.     $filePath = $_.FullName
  61.     $length = $_.FullNameLength
  62.     $string = "$length : $filePath"
  63.    
  64.     if ($writeToConsoleAsWell) { Write-Host $string }
  65.     $stream.WriteLine($string)
  66. }
  67. $stream.Close()
  68. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement