Folks:
I have a folder containing files with very long names that look like:
"105723456322 Three Singles To Adventure (123456) - English titles"
I can run the "Dir" command & pipe the results to a text file. I would
like
to be able to extract various strings from these file names.
* How to extract the strings "123456" and 105723456322" then pipe the
results to some text file ?
Thanks,
JoJo.
[Cross-post to ,microsoft.public.win3x_wfw_dos removed as apparently
irrelevant]
Suggest you look at alt.msdos.batch.nt & the FAQ in that group for many,
many examples.
"piping" means transferring the output of one command to the next. If you
are outputting to a text file, then you probably want to REDIRECT using the
">" (redirection) operator which sends the output of a command to a file
rather than the default output device (the console.)
Extracting strings is relatively simple - but your specification is far too
vague for a useful answer.
For instance, if you are using the "/b" switch to get your DIR listing (DIR
/B) then the output will be filename-only and not include the date/time,
size, etc.
We can't determine from your description whether you want precise substrings
or whether there's a better way. For instance, if the "123456" is always
contained in the first parenthesis-pair in your DIR line, then the command
for /f "tokens=2delims=()" %%i in ( ' dir /b ' ) do echo %%i >>filename.txt
would list that character string.
If the "105723456322" is the first space-separated token on the line, then
for /f %%i in ( ' dir /b ' ) do echo %%i >>filename.txt
will list those items.
If you want both, then they'd have to be combined - not a particularly
arduous task, but a lot easier if there's a better specification.
To substring in general, the command is
SET substring=%varname:~m,n%
where m is the start position, counting from 0 as the first character and n
is the length (and optional.)
But this is unlikely to be particularly useful where the data is as you've
implied - a variable-length title containing multiple space-separated words.