Page 1 of 1

Searching for file owners, but struggling with space in name

Posted: 23 Apr 2008 07:22
by adrianodl
Hi there,
i am just writing a simple script to go through a given list of file names (the list is in a txt file), performing a DIR /q into it and sending the results to an output file.

for /F %%i IN (confidentiallist.txt) do dir /q %%i >> owner-confidential.txt

The issue i am facing when running the batch file is that, whenever a file or folder has a space in it, the command is broken and not performed accordingly. Ex: if the input file has such a file -
c:program file\icq\icq60.exe
the result i get is:

DIR C:\Program
File not found

which means that everything after the space is being ignored. I tried to put the whole parameter in double quotes, such as
"c:\program files\icq\icq60.exe", but still getting the same error.

I know it might be piece of cake for you guys, but i am struggling with it for quite some time, and haven't found a clear answer to this issue.

Regards,
Adriano.

Posted: 23 Apr 2008 16:04
by jeb
Hi,

the for loop is the main problem the default delimiter is a space,
so you got in %%i only the first part. Quotes dont help there.

First you need to get the full line with "tokens=*"

Then you have to get the correct directory with "%%i"
ex. "Program Files" else you get "Program" and "Files"

This works

Code: Select all

for /F "tokens=*" %%i IN (confidentiallist.txt) do dir /q "%%i" >> owner-confidential.txt


jeb

thank you!

Posted: 24 Apr 2008 05:53
by adrianodl
So simple and so tricky.
Thank you again!