Discussion:
For /f in (filename.txt) doesn't like spaces in line values - any help?
(too old to reply)
.
2010-05-19 12:56:38 UTC
Permalink
On Windows XP this is what I'm doing...

Make a batch file to manually scan a system drive,
currently ClamAV's gui doesn't do it, it only scans
for open files and running processes. My problem
is when the for loop reads the text file, if there's a space
in the text it only rads the first part, it hits the space
and goes to the next line.

My question - how can I have it read the full line including
the spaces? I've searched a bit but can't find the answer.
Hoping you batch file guru's can help me out ;-)

I'll give credit to whom credit is do oh great ones!

********************************************************************

:: Get a directory listing from the root system drive

%systemdrive%
cd\
dir /AD /B > dirs.txt

:: Now, lets scan with ClamAV all our directories

:: Change to ClamAV's Windows Directory

cd %ProgramFiles%\ClamAV for Windows\1.0.26"

for /f %%i in (c:\dirs.txt) do agent -d "%systemdrive%\%%i"

********************************************************************

dirs.txt file contents:

18051861446c3b9886
6541fd42d4b32dc25a13c9b65107
9b767b163a3212d9d2fd65bd
dell
Documents and Settings
drivers
i386
MSOCache
MySlaxTemp
NVIDIA
Program Files
RECYCLER
sysprep
System Volume Information
temp
WINDOWS

********************************************************************

ClamAV kicks off a scan just fine and dandy, it iterates through
each folder in the text file UNTIL it hits one with a space like
Program Files or Documents and Settings.

What I don't understand is I have it quoted but I don't think
it's my quotes, it seems to be a problem with how the command
line is reading the text file, it hits a space and moves to the next
line. Is there any way to have it read the whole line in the text
file?

Error output is this:

C:\Program Files\ClamAV for Windows\1.0.26>agent -d "C:\Documents"
May 19 08:58:20: ERROR: Scan::Directory: unable to open directory :
3 : The syst
em cannot find the path specified.


Thanks!
foxidrive
2010-05-19 13:01:34 UTC
Permalink
Post by .
Make a batch file to manually scan a system drive,
currently ClamAV's gui doesn't do it, it only scans
for open files and running processes.
My question - how can I have it read the full line including
the spaces? >
********************************************************************
:: Get a directory listing from the root system drive
%systemdrive%
cd\
dir /AD /B > dirs.txt
:: Now, lets scan with ClamAV all our directories
There should be no need to Change to ClamAV's Windows Directory

Try this:

set file="%ProgramFiles%\ClamAV for Windows\1.0.26\agent"

for /f "delims=" %%i in (c:\dirs.txt) do %file% -d "%systemdrive%\%%i"



The "delims=" sets the delimiter to nothing. It defaults to spaces and TABs.
--
Regards,
Mic
.
2010-05-19 13:24:01 UTC
Permalink
Post by foxidrive
Post by .
Make a batch file to manually scan a system drive,
currently ClamAV's gui doesn't do it, it only scans
for open files and running processes.
My question - how can I have it read the full line including
the spaces? >
********************************************************************
:: Get a directory listing from the root system drive
%systemdrive%
cd\
dir /AD /B > dirs.txt
:: Now, lets scan with ClamAV all our directories
There should be no need to Change to ClamAV's Windows Directory
set file="%ProgramFiles%\ClamAV for Windows\1.0.26\agent"
for /f "delims=" %%i in (c:\dirs.txt) do %file% -d "%systemdrive%\%%i"
The "delims=" sets the delimiter to nothing.  It defaults to spaces and TABs.
--
Regards,
Mic
Thanks Mic...that was BLAZINGLY fast!!!

That worked.
foxidrive
2010-05-19 13:40:32 UTC
Permalink
Post by .
Post by foxidrive
for /f "delims=" %%i in (c:\dirs.txt) do %file% -d "%systemdrive%\%%i"
Thanks Mic...that was BLAZINGLY fast!!!
That worked.
You're welcome.


If you also change that line above to this then it will work in any
folder you start with.

for /f "delims=" %%i in (c:\dirs.txt) do %file% -d "%%i"
--
Regards,
Mic
Teju Thejasvi
2023-06-16 05:54:40 UTC
Permalink
Im appending test2 data by skipping the first row to test1 data but im having the files in a folder which uses space in its path. Please advice
set myPath="C:\Users\Documents\Test Folder"
for /F "skip=1 delims=" %%A IN (%myPath%\test2.dat") do (echo %%A)>> %myPath%\test1.dat
Loading...