1
votes

I am running into an issue where I have a complete directory listing of a computer (located in the text file shown below).

The issue appears in cases where the directory listing contains special characters such as "! or &". When that issue occurrs, the filename is parsed such that those special characters are omitted (thus causing issues with leveraging those variables to compute other sub-tasks). Below is a snapshot of the code. Please advise as to how I might proceed.

Note that within the text file might be paths such as:

C:\Windows!temp!\file.txt C:\Windows\file.txt

This will parse as:

C:\Windows\temp\file.txt (without quotes) C:\Windows\file.txt


code snip

 for /f "delims=?" %%a in (dir.txt) do (
 setlocal enabledelayedexpansion
 set filepath=%%a
 )
 call :subproc1
 )
 goto :proc2

 :subproc1
      echo !filepath!
      endlocal
      goto :eof

 :proc2 
      continue with script here
2
why do you have two closing brackets after the for? - npocmaka

2 Answers

1
votes

You are toggling delayed expansion on too early, and there is no need for the subroutine.

for /f "delims=?" %%a in (dir.txt) do (
  set filepath=%%a
  setlocal enabledelayedexpansion
  echo !filepath!
  endlocal
)
0
votes
@echo off

setlocal enableDelayedExpansion
for /f "delims=?" %%a in (dir.txt) do (
    setlocal disableDelayedExpansion
    (echo(%%a)
    endlocal
)
endlocal

goto :proc2


:proc2 
     echo -------end

the Jeb's trick...