Batch: list filenames without extension
Solved
Profile blocked
-
Tym -
Tym -
```batch
@echo off
for /f "delims=. tokens=1" %%f in ('dir .\dossier\*.ext /b /o:n') do echo %%f >> liste.txt
```
@echo off
for /f "delims=. tokens=1" %%f in ('dir .\dossier\*.ext /b /o:n') do echo %%f >> liste.txt
```
4 answers
Hello,
It is possible to perform this operation in a more elegant and certainly more reliable way:
@ECHO OFF
DEL liste.txt
FOR /F %%I IN ('DIR .\folder\*.ext /B /O n') DO ECHO %%~nI >> liste.txt
Indeed, the ~n format option allows you to get only the file name without the extension.
The problem with the previous method is that if the file name contains a “.” (for example: “file.with.dots.ext”, the file name will be truncated (only “file” will remain in the previous example).
I hope this will be useful to some.
Best regards,
Tym
It is possible to perform this operation in a more elegant and certainly more reliable way:
@ECHO OFF
DEL liste.txt
FOR /F %%I IN ('DIR .\folder\*.ext /B /O n') DO ECHO %%~nI >> liste.txt
Indeed, the ~n format option allows you to get only the file name without the extension.
The problem with the previous method is that if the file name contains a “.” (for example: “file.with.dots.ext”, the file name will be truncated (only “file” will remain in the previous example).
I hope this will be useful to some.
Best regards,
Tym
Try it
Keep me updated!
Bilou.
--
There are days you shouldn't mess with me.
And there are days every day!
@echo off for /f "tokens=1 delims=." %%i in ('dir .\folder\*.ext /b /o n') do echo %%i >list.txt Keep me updated!
Bilou.
--
There are days you shouldn't mess with me.
And there are days every day!
Thank you very much, after a slight modification I got what I wanted:
@echo off
del liste.txt
for /f "tokens=1 delims=." %%i in ('dir .\dossier\*.ext /b /o n') do echo %%i >>liste.txt
The previous code listed the files in liste.txt but overwrote each time, so in the end I only had one name in liste.txt (the last one in the list).
By adding >> instead of >, I had all the names, but if I reran the batch it would relist the already present files, hence the addition of a little del to delete the file before creating a new one.
Thanks again for your precious help.
@echo off
del liste.txt
for /f "tokens=1 delims=." %%i in ('dir .\dossier\*.ext /b /o n') do echo %%i >>liste.txt
The previous code listed the files in liste.txt but overwrote each time, so in the end I only had one name in liste.txt (the last one in the list).
By adding >> instead of >, I had all the names, but if I reran the batch it would relist the already present files, hence the addition of a little del to delete the file before creating a new one.
Thanks again for your precious help.