Searching for file owners, but struggling with space in name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
adrianodl
Posts: 2
Joined: 23 Apr 2008 07:10

Searching for file owners, but struggling with space in name

#1 Post by adrianodl » 23 Apr 2008 07:22

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.

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#2 Post by jeb » 23 Apr 2008 16:04

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

adrianodl
Posts: 2
Joined: 23 Apr 2008 07:10

thank you!

#3 Post by adrianodl » 24 Apr 2008 05:53

So simple and so tricky.
Thank you again!

Post Reply