Gurfaild

joined 2 years ago
MODERATOR OF
[–] Gurfaild@feddit.de 1 points 1 year ago (1 children)

Kommt drauf an, ob du von CSUlern denunziert werden willst

[–] Gurfaild@feddit.de 2 points 1 year ago

Then the snippet won't work because it only ever renames/copies the file '_2023 Summary Page.docx'. What are the actual names of the files you want to rename?

[–] Gurfaild@feddit.de 1 points 1 year ago* (last edited 1 year ago) (2 children)

Just use Copy-Item instead of Rename-Item if you want multiple identical files with different names

[–] Gurfaild@feddit.de 2 points 1 year ago* (last edited 1 year ago) (4 children)

That will crash if there is more than one line in individuals.txt, because by the second iteration '.\_2023 Summary Page.docx' has been renamed.

[–] Gurfaild@feddit.de 1 points 1 year ago* (last edited 1 year ago)

I have no idea why this wouldn't work on your machine - I've tested it on mine and it works fine. So maybe you have overlooked some small things:

  • If there are any other PDFs in the directory that you don't want to rename, then the list of files is longer than the list of names.

  • If the PS window closes completely, you might have typed it into the terminal instead of running it as a script - then the problem might just be that you closed the if block too early, so PS immediately executes the exit command.

  • If your list of new names contains a column label like in a one-column CSV, then it has one more line than there are files.

[–] Gurfaild@feddit.de 12 points 1 year ago

Geizhals hält sich dran, das ist aber wirklich die einzige kommerzielle Seite, bei der ich das gesehen habe

[–] Gurfaild@feddit.de 3 points 1 year ago* (last edited 1 year ago) (18 children)

If the CSV file contains both the current names and the new names, this should work if you use the first line for column labels (I'm using OldName and NewName in this example):

Import-CSV $pathToCSV | ForEach-Object { Rename-Item $_.OldName $_.NewName }

If you just have a list of new names as a text file where the first line of the file is the new name for the first file (by name, sorted alphabetically), this should work:

$files = Get-ChildItem -File *.pdf | Sort-Object -Property Name #I think the output of Get-ChildItem is already sorted by name, but I'm not sure
$newNames = Get-Content $pathToTXT
if ($files.Count -ne $newNames.Count) {
    Write-Error "The number of PDF files to be renamed does not match the number of new names"
    exit
}
0..($files.Count - 1) | ForEach-Object { Rename-Item $files[$_] $newNames[$_] }

[–] Gurfaild@feddit.de 3 points 1 year ago

According to Kamil Galeev, it would be more accurate to claim that both the Soviet Union and modern Russia operate mostly the same way as Tsarist Russia did

[–] Gurfaild@feddit.de 14 points 1 year ago

Deswegen gehe ich möglichst durch enge Gassen, wo kein Haus durchpasst

[–] Gurfaild@feddit.de 11 points 1 year ago (2 children)

Was sollen die Nachbarn sagen?

[–] Gurfaild@feddit.de 3 points 1 year ago

As usual, he's snooping

[–] Gurfaild@feddit.de 1 points 1 year ago* (last edited 1 year ago)

The problem with that is that comments that are removed by moderators behave the same way - that might actually cause legal problems if someone posts something that you're obligated to remove instead of just hiding it

view more: ‹ prev next ›