2/21/2024 0 Comments Windows mass rename files matching![]() The new name is the combination of the counter with 2-digit format and the folder name with extension. The Rename-Item is the command and in our case it takes $fullname which is the full path with the filename and the new name - "$zero$counter-$dir$extension". The next line is the actual file renaming. We are using ternary operator which test if $counter is less or equal to 9 and if true will be equal to string "0". We also want our counter to be in double digit format. If it is true the $dir will get the current name and will reset the $counter. We do that with another if block which test if $dir is not equal ( -nq). Next, we need to reset our $counter on every new folder. This is the if block if ($name -Match $fileTypes) and -Match is the RegEx parameter. Now we need a conditional which match the looped file and the $fileTypes. Within the loop we need the filename as $name the full path (including the filename and the extension) as $fullname and the file type as $extension. To start rename images, we will loop through them with foreach ($file in $files). Now we can say that $files is a collection or an array of all files in the folders we want. Having this data and with the help of the RegEx we are matching $path with FullName. First, I'm getting FullName because it is a string containing the full path and the filename.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |