Como faço para obter os primeiros 7 caracteres do arquivo?
I want the out put list of just AAAAAA , BBBBBBB, CCCCCCC , ...
Use o seguinte arquivo em lotes (para extrair as primeiras 7 letras do nome do arquivo).
test.cmd:
@echo off
@Setlocal EnableDelayedExpansion
for %%i in (*.pdf) do (
set _name=%%~ni
echo !_name:~0,7!>> c:\list.xls
)
Exemplo de saída
:
C:\test>dir *.pdf
Volume in drive C has no label.
Volume Serial Number is C8D0-DF1E
Directory of C:\test
19/06/2015 17:56 0 AAAAAAA-01.pdf
19/06/2015 17:56 0 BBBBBBB-02.pdf
19/06/2015 17:57 0 CCCCCCC-03.pdf
3 File(s) 0 bytes
0 Dir(s) 92,871,524,352 bytes free
C:\test>test
C:\test>type c:\list.xls
AAAAAAA
BBBBBBB
CCCCCCC
C:\test>
Como eu só obtenho esses personagens antes do DASH -?
For example my files are ABCD-01.pdf , A-03.pdf, AB-00.pdf, ... I want the output to be ABCD , A, AB, ...
Use o seguinte arquivo em lotes (para extrair todas as letras antes de um -
)
test.cmd:
@echo off
for /f "usebackq tokens=1 delims=-" %%i in ('dir /b *.pdf') do echo %%i>> c:\list.xls
Exemplo de saída
:
C:\test>dir *.pdf
Volume in drive C has no label.
Volume Serial Number is C8D0-DF1E
Directory of C:\test
19/06/2015 18:13 0 A-03.pdf
19/06/2015 17:56 0 AAAAAAA-01.pdf
19/06/2015 18:14 0 AB-00.pdf
19/06/2015 18:13 0 ABCD-01.pdf
19/06/2015 17:56 0 BBBBBBB-02.pdf
19/06/2015 17:57 0 CCCCCCC-03.pdf
6 File(s) 0 bytes
0 Dir(s) 92,870,991,872 bytes free
C:\test>test
C:\test>type c:\list.xls
A
AAAAAAA
AB
ABCD
BBBBBBB
CCCCCCC
C:\test>
Outras leituras