in reply to How can I use printf FORMAT strings for (Win32) shell globs?
Many thanks for the really useful suggestions, folks.. I *knew* there had to be a better way... and, as the question involved regex, I expected *lots* of options ;)
I guess I should've explained context a bit better.. and sure, example runs & data always help.. but I simply thought the question was one of 'translation' and 'substitution', so I didn't include test data and such this time around.
By way of background... I'm basically putting an 'intelligent wrapper' around 'ffmpeg', the video manipulation tool... and one of the functions I'm dealing with is the creation/usage of a sequence of frames from a video. The normal syntax for extracting frame images uses an argument like 'Img%04d.png' so that the filename is a consistent length and ffmpeg can output/input a sequence of images in-order - this is why the spec. is zero-filled - and the wrapper determines the width ('4' in this example) after having counted all the frames in the video. This also explains why I don't need to consider negative numbers, etc... and the 'fixed-width, zero-filled' format is a requirement for some subsequent processing after this wrapper creates the image files.
With Win32's CMD.exe (or 4NT.exe or TCC.exe, which I'm generally using), the shell gets confused with that '%' (even when escaped, it seems), so the string that's used on the command line is `Img%04d.png` (with the backprimes)... and that seems to work with Linux and Win32 CLI shells Ok...
The wrapper does some checks with the string before it calls ffmpeg to see if there are any pre-existing, conflicting files... but I admit I'm slack in that I only considered using glob(), as I thought (unjustifiably?) it might be the simplest method and it might work better than using something like File::Find, particularly when checking for 10s of 1000s of (frame image) files per video... and I *did* forget that File::Find IS core in Perl these days... Ooop!
Anyway, the original code was purposely 'ordinary' as I'm *still* not so flash with regex and I wanted to be sure I properly understood what each part of the code was doing.
Certainly, there are a lot of *most helpful* postings here now, Fanx!... so I can try some more elegant methods.. and see which one best suits what I'm trying to do.
Fanx! again, everyone...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I use printf FORMAT strings for (Win32) shell globs?
by soonix (Chancellor) on Jul 18, 2017 at 09:34 UTC | |
by ozboomer (Friar) on Jul 19, 2017 at 00:15 UTC | |
|
Re^2: How can I use printf FORMAT strings for (Win32) shell globs?
by haukex (Archbishop) on Jul 19, 2017 at 06:37 UTC | |
|
Re^2: How can I use printf FORMAT strings for (Win32) shell globs?
by RonW (Parson) on Jul 20, 2017 at 20:33 UTC |