Advertisement
AInonymous

Untitled

Dec 6th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. # Specify the directory path
  2. $directoryPath = "C:\Folder with your merged files"
  3.  
  4. # Get all text files in the specified directory
  5. $textFiles = Get-ChildItem -Path $directoryPath -Filter *.txt
  6.  
  7. # Process each text file
  8. foreach ($file in $textFiles) {
  9. # Read the content of the file
  10. $content = Get-Content -Path $file.FullName -Raw
  11.  
  12. # Remove the last space from the content
  13. $content = $content.TrimEnd()
  14.  
  15. # Write the modified content back to the file
  16. $content | Set-Content -Path $file.FullName -NoNewline
  17. }
  18.  
  19. Write-Host "Operation complete. Last space removed from text files in $directoryPath."
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement