Test script for a valid filename regex:
Code: Select all
@ECHO off
FOR /F "tokens=2 delims=:." %%X IN ('CHCP') DO SET codepage=%%X
CHCP 1252>NUL
SET "name=AVRO: [Wié*,/ïs dê\ Mòl?!] (08012009^)"
CHCP %codepage%>NUL
ECHO %name%
ECHO %name% | xidel.exe -q - -e "replace(replace($raw,':','-'),'[<>:\"/\\\^|?*]','')"
FOR /F "delims=" %%A IN ('ECHO %name% ^| xidel.exe -q - -e "replace(replace($raw,':','-'),'[<>:\"/\\\^|?*]','')"') DO ECHO %%A
Code: Select all
AVRO: [Wié*,/ïs dê\ Mòl?!] (08012009)
AVRO- [Wié,ïs dê Mòl!] (08012009)
"') DO ECHO %A was unexpected at this time.
Xidel is a wonderful piece of software that lets me use XPath/XQuery in Batch. It first replaces the colon with a dash, because colons aren't allowed in a filename. If it then encounters any of the invalid filename characters (between squarebrackets), it will remove those.
The first xidel-command works fine, but my question is about the for-loop. I've tried to double escape the pipes, escape the less/greater than signs and tried numerous other things, but no matter what I always end up with ""') DO ECHO %A was unexpected at this time.".
Does anyone know how I can make the for-loop work?