I am trying to write a script in powershell to batch convert video files.
The way I intend to use this is to go to some folder full of video files and run it. It uses a conversion program that can be run in "command line mode" (named handbrake) and saves files with "-android" added to them before the file extension. For example, if I have a file called video1.avi in ββa folder, after running the script, the folder has 2 files: video1.avi and video1-android.avi
The reason I want to do this is to check that for each video file there is a converted version (with the addition of -android to the name). And if so, skip the conversion for this file.
And here I have problems. The problem is the behavior of Test-Path (the cmdlet I use to check if the file exists).
What happens if the video file has an βunusualβ name (for example, in my case this video is [long] .avi) Test-Path always returns False if you try to check if this file exists.
A simple way to check this, for example, for this:
Go to an empty folder, run Notepad to create a file with "[" in its name:
¬epad test[x].txt
Save file
then do the following:
Get-ChildItem | ForEach-Object {Test-Path $_.FullName}
This does not return true! It is right? Well, this is not the case if the file has a β[β in its name (I have not checked any other special characters)
I realized that if you avoid the "[" and "]", it works
Test-Path 'test`[x`].txt'
returns true.
? : BaseName , "-android.avi" , .
,