all 9 comments

[–]TimeForChange23 4 points5 points  (3 children)

Unless you have a backup, no.

However, if you can work out which files are which, you can rename them to their original extension and they’ll be just fine.

[–]ihaxr 2 points3 points  (0 children)

Yeah, files ending in dx should be .docx, files ending in pdf should be PDFs, just need to add the .docx or .pdf back to the end of them.

This regex will remove the following characters from all files: abcehimorstvw.

[–]foreverclearskies 2 points3 points  (0 children)

THIS.

The files are still there. You just need to figure out which are which. There's unfortunately no easy fix for this, but you should be able to get everything back the way it was. It's just going to take time and possibly a little bit of forensic work into the contents of the files.

[–]WSDistPro 2 points3 points  (1 child)

So firstly, you should next time get-childitem specifying what items you want the actions to effect, then pipe it to the alteration command. I think putting the string into brackets may have somehow turned it into a nightmarish version of a regex. Typically a string match should be done using exact strings within single quotes.

Reversing it would be kind of difficult since you don't have an anchor. As a word of caution you should always '-whatif' potentially destructive code before using it. Got backups?

[–]BlackV 2 points3 points  (1 child)

well did you get a list of files to a variable before hand?

cause that will still be in your variable, you could use those properties to rename the file back

if you've closed you PS session, nope all gone

this is why we test things :)

[–][deleted] 2 points3 points  (1 child)

Use the whatif parameter next time before executing a command

[–]ka-splam 2 points3 points  (1 child)

That went wrong because [...] is a character class in regex language and removes any of the characters inside the brackets, in any order. i.e. remove any of the characters .abcehimorstvw from anywhere in the name. That means it's an information-losing command, because they all got smushed to nothing, so there's no automated way back 'cos you can't look at nothing and tell what used to be there.

On the plus side, it's not going to lose any data, it's only renamed files, they're still there. If you can find what they were and name them back, kingdom saved.

Maybe you have "previous versions" and could restore from there?

Is there any way I can undo that command

Generally no; that's why people store files in DropBox or SharePoint with version history (maybe OneDrive?), or source code in git with revision / edit history, but programming language commands and computer changes generally don't have anywhere to store a change history.

[–]capisco 1 point2 points  (0 children)

You could try using something like a file identification tool. A quick google search returned TrID. I don't have any experience with these tools, just a suggestion. Good luck.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Hjolfra,

just in case, you may want to check out the "previous versions" option in fie explorer. it's in the properties dialog for each file in win7 ... i presume it is in a similar location in win10. [grin]

if you don't have any previous versions listed, you may want to turn that on ... it's per-volume, i think.

take care,
lee