I had a batch file, which (when simplified) looked like this:
@Echo Off
SetLocal EnableDelayedExpansion
    MD "MyProgram^!"
    MD "MyProgram version 2"
    MD "MyProgram (next version)"
    MD "MyProgram O&O"  
    Del Folders.txt
    Call :AddFoldersRecursive .
EndLocal
Goto :EOF
:AddFoldersRecursive FolderPath
    Echo %~1>>Folders.txt
    For /D %%f In ("%~1\*") Do  Call :AddFoldersRecursive "%%~f"
Goto :EOF
It brought up all kinds of errors when facing different kinds of file names in different situations:
- MyProgram version 2couldn't be echoed, because- 2>>was interpreted incorrectly.
- MyProgram (next version)couldn't be echoed, because parentheses had to be- ^escaped.
- MyProgram O&Ocouldn't be echoed, because of the- &symbol
- MyProgram!couldn't be echoed, because of the- !symbol
Is there any solution which works for all such situations (including combinations and nesting, etc.)?
(ASCII is fine -- I don't need Unicode support right now.)
 
     
    