I am just about completing my script on copying a folder structure for every line in a textfile. We want a folder with subfolders for every customer. The customer "Test" folder should be placed in \path\e$\Relaties\T\Test. So for every beginletter a specific folder and for the rest like numbers or characters an "_Overig" (other) folder.
This all works fine, but I have problems with special characters like %* / \ ' " and so on. In the example beneath, I want to delete all 's in the foldername, since Windows does not support that. I do this with set var=!var2:=! but it does not work. Also, when a line in the textfile contains an !, the script also crashes. I can escape it by putting ^! instedad of ! in the batch file, but since it is generated by our intranet I want the batch file below just to deal with !'s and escape it by itself.
Please help me out.
setlocal EnableDelayedExpansion
set file=E:\list.txt
FOR /F "delims=~" %%i IN (!file!) DO (
echo %%i
set var2=%%i
set var=!var2:*=!
set str=!var:~0,1!
IF /i !str!==A ( set letter=1&&set str=A)
IF /i !str!==B ( set letter=1&&set str=B)
IF /i !str!==C ( set letter=1&&set str=C)
IF /i !str!==D ( set letter=1&&set str=D)
IF /i !str!==E ( set letter=1&&set str=E)
IF /i !str!==F ( set letter=1&&set str=F)
IF /i !str!==G ( set letter=1&&set str=G)
IF /i !str!==H ( set letter=1&&set str=H)
IF /i !str!==I ( set letter=1&&set str=I)
IF /i !str!==J ( set letter=1&&set str=J)
IF /i !str!==K ( set letter=1&&set str=K)
IF /i !str!==L ( set letter=1&&set str=L)
IF /i !str!==M ( set letter=1&&set str=M)
IF /i !str!==N ( set letter=1&&set str=N)
IF /i !str!==O ( set letter=1&&set str=O)
IF /i !str!==P ( set letter=1&&set str=P)
IF /i !str!==Q ( set letter=1&&set str=Q)
IF /i !str!==R ( set letter=1&&set str=R)
IF /i !str!==S ( set letter=1&&set str=S)
IF /i !str!==T ( set letter=1&&set str=T)
IF /i !str!==U ( set letter=1&&set str=U)
IF /i !str!==V ( set letter=1&&set str=V)
IF /i !str!==W ( set letter=1&&set str=W)
IF /i !str!==X ( set letter=1&&set str=X)
IF /i !str!==Y ( set letter=1&&set str=Y)
IF /i !str!==Z ( set letter=1&&set str=Z)
IF !letter!==1 ( set pad=\\fs1\e$\Data\Relaties\!str!\!var!) ELSE (set pad=\\fs1\e$\Data\Relaties\_Overig\!var!)
set oudpad=\\fs1\e$\Data\Klanten\!var!
xcopy "\\fs1\e$\Data\Relaties\_template\_template" "!pad!" /T /E /O /I
robocopy "!oudpad!\adviesrapporten" "!pad!\Documentatie\Adviesrapporten" /ZB /COPY:DAT /R:3 /W:1
set letter=0
)
Edit:
Fixed the asterisk thing by using set var=!var:**=!
But still if I want a foldername with an ! in it, the script ignores it.