I have a large number of files in a folder structure.
I need to address them via a batch.
How do I get the first letter of a filename?
Structure:
\A\A
\A\AUHUIHHU
\A\AZZZAHHH
\B\BABBBA
\B\BUHAHHA
etc.
Filenames can start with letters A-Z and numbers 0-9.
I have the filename in %1
Example:
BUHAHHA
Batch:
COPY \B\BUHAHHA \TEMP\
So, I need the \B\ from the first letter of BUHAHHA
Foldername first letter of filename
Moderator: DosItHelp
Re: Foldername first letter of filename
All you need is assigning it to a regular environment variable. Then use the substring syntax as described in the help of the SET command.
Code: Select all
set "initial=%~1"
set "initial=%initial:~0,1%"
Re: Foldername first letter of filename
Thanks. I was not aware of the substring options.
Re: Foldername first letter of filename
Mmmm.... Why do you need the first letter of the filename? Are not all files that start with "A" in a folder named "A"? And the same for the rest of letters?
Antonio
Antonio