Page 1 of 1

Foldername first letter of filename

Posted: 16 Jan 2019 13:10
by STEPHAN
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

Re: Foldername first letter of filename

Posted: 16 Jan 2019 16:21
by aGerman
STEPHAN wrote:
16 Jan 2019 13:10
I have the filename in %1
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%"
Steffen

Re: Foldername first letter of filename

Posted: 16 Jan 2019 16:59
by STEPHAN
Thanks. I was not aware of the substring options.

Re: Foldername first letter of filename

Posted: 17 Jan 2019 09:56
by Aacini
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