6
1
Here's what I have:
C:\test\12345-test1.txt
C:\test\23456-test2.txt
C:\test\44444-test3.doc
I would like to have the script read the first 5 digits from the file, create a folder with those digits, and include the letter T before it.
The result after running should be like this:
C:\test\T12345\12345-test1.txt
C:\test\T23456\23456-test2.txt
C:\test\T44444\44444-test3.doc
Currently, I have this, which does the function; I just can't figure out where to put the SET command to extract the 5 characters.
@echo off
for %%a in (*.*) do (
md "T%%a" 2>nul
move "%%a" "T%%~a"
)
I think this needs to be added to choose only the first 5 characters:
set first5=%%a:~5,1%
Thoughts?
Thank you for the answer, I am just not sure how to compile it together to make it work.
for %%a in (.) do ( set first5=%a:~0,5% md "T%%a" 2>nul move "%%a" "T%%a" )
If you want to access some variable, use
%varname%
, not%%varname
. Tryecho %first5
. You never used first5 after SETting it? – Jens Erat – 2011-10-25T19:10:13.380Could you provide some explanation about what your code does? – Tamara Wijsman – 2011-10-31T21:42:09.830
Did so. As these are primarily very basic operations I recommend you to have a look at some batch-tutorials (can't reference any, sorry - have a look yourself, most look a lot like beepworld and 90's but are still fine). More information about set can be got by calling set help
set /?
. – Jens Erat – 2011-11-01T00:10:13.810