1

I've been trying to make a batch file that makes folders named after the people on a .txt file list, and then gives them full access to modifying their own personal folder.

The problem is that I keep getting a ' delims= " was unexpected at this time' error.

Here's my code here, I was wondering if you guys would be able to find out what I did wrong, thanks ^-^

(Btw I haven't added the permissions part yet, I just need to get this part sorted out first)

CODE: http://pastebin.com/XLi11nZa NAMES LIST: http://pastebin.com/xbh3WTSv

@echo off
color A
echo What is the name of list file? (Do not include format)
SET /P list=
setlocal EnableDelayedExpansion
set "cmd=findstr /R /N "^^" %list%.txt | find /C ":""
for /f %%a in ('!cmd!') do set m=%%a
SET c=0
echo !m! folders to be created. Continue? (Y/N)
SET /P ANSWER=
if /i {%ANSWER%}=={y} (goto :yes) 
if /i {%ANSWER%}=={yes} (goto :yes) 
exit
:yes
echo Now creating %m% folders.....
for /f "eol=; tokens=1 delims=," %%i in ("%list%.txt") do (  
SET /a c = !c! + 1
mkdir "%%i"
echo !c!/%m% folders created [%%i]
)
endlocal
echo Now adding permissions to  %m% folders.....
pause
setlocal enabledelayedexpansion
SET c1=0
for /f "eol=; tokens=1 delims=," %%i in ("%list%.txt") do (  
SET /a c1 = !c1! + 1
SET word=1
SET /a showme=c1-1
SET showme=skip=%showme%
IF !c1! equ 1 set "showme= "
FOR /F "tokens=%word% %showme% delims= " %%F IN ("%list%") DO if defined 

showme set showme=%%F
SET first=%showme:~0,1%

SET word=2
SET /a showme1=c1-1
SET showme1=skip=%showme1%
IF %c1% equ 1 set "showme1= "
FOR /F "tokens=%word% %showme1% delims= " %%L IN ("%list%") DO if 

defined showme1 set showme1=%%L
set B=%showme1%%first%

set _STRING=%B%

set "_UCASE=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set "_LCASE=abcdefghijklmnopqrstuvwxyz"

for /l %%a in (0,1,25) do (
   call set "_FROM=%%_UCASE:~%%a,1%%
   call set "_TO=%%_LCASE:~%%a,1%%
   call set "_STRING=%%_STRING:!_FROM!=!_TO!%%
)

set _STRING
echo %_STRING%
echo %_STRING%>>testing.txt

endlocal
pause
)

names list

Loralee Stucky
Tomas Silberman
Marleen Rosell
Phyllis Steier
Elmo Jetter
Kristyn Spruell
Willetta Vandermeer
Hazel Alsobrook
Naida Nixon
Nadia Godfrey
Lavonna Antunez
Mac Castile
Tamela Stover
Piedad Heidrick
Hien Welsh
Carolin Gularte
Mariko Tolentino
Alia Graddy
Deadra Rehkop
Donella Pittman
foxidrive
  • 40,353
  • 10
  • 53
  • 68
Plexiscore
  • 11
  • 1
  • 2
  • Instead of `set /P` for a simple Yes/No prompt you could also use `choice` -- type `choice /?` for info. (note this is not a build-in command). – aschipfl Aug 01 '15 at 11:18

2 Answers2

2

Replace

for /f "eol=; tokens=1 delims=," %%i in ("%list%.txt") do (

by

for /f "usebackq eol=; tokens=1 delims=," %%i in ("%list%.txt") do (

twice.
Without the usebackq option, a double-quoted set of for /F is interpreted as a literal string rather than a file. Removing the double-quotes could work but could also lead to problems with files that have spaces in their names.


Another thing: you are dynamically creating the skip=# option for for /F, where # stands for a number. you have to make sure that this number is always positive, so 0 is not understood by for /F which could also lead to your error message.
So you could add an if check whether the number is greater than zero and do not add the skip option otherwise (by clearing your showme variables).


And last but not least: the delayed expansion is not always used properly: sometimes in the block startung at the for command in line #26 of your code and reaching to the end, you are not consistently using !! for expansion of variables showme, showme1 and c1, which are the ones that are modified within that code block.

Community
  • 1
  • 1
aschipfl
  • 33,626
  • 12
  • 54
  • 99
0

The folders will get created proper if you remove the double quotes from the filename variable for /f "eol=; tokens=1 delims=," %%i in (%list%.txt) do ( change that line and you'll get past this part. You may want to do the same in the permissions section.

BasicIsaac
  • 187
  • 8