You are not logged in.
Hi:)
I have this .bat to save the list of files in a folder
@echo off
chcp 1252
SET NOMEFILE=%TEMP%\FILES.TXT
IF EXIST %NOMEFILE% DEL %NOMEFILE%
FOR /F "delims=;" %%x in ('dir /b %1') do CALL :NOESTENSIONE "%%x" >> %NOMEFILE%
NOTEPAD %NOMEFILE%
DEL %NOMEFILE%
GOTO :EOF
:NOESTENSIONE
ECHO %~n1
GOTO :EOF
The bat file work fine but does not work with special characters like "&". Can you help me?
Thanks:)
Offline
The & symbol is a continuation character, so will need to be escaped.. or:
The simplest solution is to use quotes for the assignment, and delayed expansion. This eliminates any need for escaping.
https://stackoverflow.com/questions/141 … -win-batch
Offline
sorry but I'm not expert at all. I found this .bat but I can not change it Could you do it? Thank you
Offline
You just need to put quotes around the variable expansions, but one will need delayed expansion.
@echo off
chcp 1252
if not exist "%~1" exit /b 1
set "nomefile=%temp%\FILES.TXT"
>nul copy nul "%nomefile%"
for /f "delims=;" %%X in (' dir /b "%~1" ') do call :NOESTENSIONE "%%~X" >> "%nomefile%"
notepad "%nomefile%"
if exist "%nomefile%" del "%nomefile%"
exit /b 0
:NOESTENSIONE
setlocal DisableDelayedExpansion
set "_n1=%~n1"
setlocal EnableDelayedExpansion
echo(!_n1!
goto :eof
Last edited by Pyprohly (08 Jul 2018 15:16)
Offline
Thanks! Is perfect!
Last edited by Lauraq (08 Jul 2018 18:34)
Offline
Should be able to avoid delayed expansion altogether (and simplify to remove the need of the subroutine call). Untested, but I think this should do it:
@echo off
chcp 1252
if not exist "%~1" exit /b 1
set "nomefile=%temp%\FILES.TXT"
(
for /f "delims=;" %%X in ('dir /b "%~1" ') do (
set /p "OUT=%%~nX" <nul
echo:
)
) > "%nomefile%"
notepad "%nomefile%"
if exist "%nomefile%" del "%nomefile%"
exit /b 0
cmd | *sh | ruby | chef
Offline
Thanks, this works perfectly too
Last help...is there a way to have a list of only 2 types of files (mp3 and flac) and exlcude all the other tipe of files?
Thank you
Offline
Assuming the parameter is a directory name:
@echo off
chcp 1252
set "nomefile=%temp%\FILES.TXT"
set "file_mask=*.mp3 *.flac"
if not exist "%~1"\* exit /b 1
pushd "%~1" || exit /b 1
>"%nomefile%" (
for /f "delims=;" %%X in (' dir /a:-d /b %file_mask% ') do (
set/p"=%%~nX"<nul
echo(
)
)
popd
notepad "%nomefile%"
if exist "%nomefile%" del "%nomefile%"
Offline
perfect! you are very kind!
Thanks for all
Offline