A
A
andreystrelkov2016-06-01 06:27:55
PowerShell
andreystrelkov, 2016-06-01 06:27:55

How to use Powershell to find files in a directory by mask and change certain text in them?

Good afternoon, please help with the task
There is a PREVIEWS folder , let's say there are thousands of other folders in it,
you need to find all files with the svg extension and having img_
in the name, and then change .png to .jpg in each file found inside

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2016-06-01
@yellowmew

1. get a list of files.
there are two ways:
the second, in your case, should seem to work faster, because it returns not FileInfo objects, but only the file path.
Then we immediately feed it to the conveyor and process it as you need.
like so.
did not deal with such a volume of files at all, and, most likely, a lot of memory will still be occupied.
But check - you)

G
globuser, 2016-06-01
@globuzer

An interesting question, with the help of PowerShell and Bash, you can do this to anyone.
But one more way, maybe not the best, but not very complicated, is to use, for example, TotalCommander, enter the main folder, press a key combination that recursively opens all folders and displays all files in this folder - you will just have one list (ctrl+b like). Then, using maxi, select files with img_ and opening each file in a text editor for editing, simply autocorrect to replace png with jpeg (such as ctrl + h).
If there are not many such files, then it is quick to do so. The word is not much - relatively, a hundred files can be done in a couple of minutes really.
But if you think and write a script on the shell, as you want, it will be faster, but the time will be spent writing the script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question