Computing.Net > Forums > Programming > Can't put quotes around files names

Can't put quotes around files names

Reply to Message Icon

Original Message
Name: masimar
Date: May 13, 2006 at 17:30:48 Pacific
Subject: Can't put quotes around files names
OS: na
CPU/Ram: na
Model/Manufacturer: na
Comment:


Here's my dilemma of the day. I'm writing a batch program built around 7za.exe to xcopy files to a destination then zip the directories, replacing them. If I do a dir thus
dir /b /a-d %path% >root.txt
for /f "tokens=1 delims=" %%i in (root.txt) do echo "%%i">>rootfls.txt
where the path is the destination and I want to find the copied files in the root of it, this works great. It also works for the directories.
But if multiple folders were too big to zip, and I want to find them and zip the subdirectories, I can't get the quotes to work because of the multiple variables.
The directories work fine, but a single file like New File.txt comes out "New"

I'm using
for /f "tokens=1 delims=" %%i in (the file where the directory names are) do for /f %%j in (the files) do echo %%j
I just can't get past the first space of the second file. I'm a beginner with variables.
If I use a vb script for input source/destination
I have the same problem with quotes around the variables.

Could somebody show me the way? My knowledge and grasp are limited, but I need a way of solving this.

I thought about and tried various ways to get short file names, but that would really mar the simplicity of replacing a directory with a zip of the same name, then unzipping the same.

Mark


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: May 14, 2006 at 01:20:47 Pacific
Reply: (edit)

Replace the statement

for /f "tokens=1 delims=" %%i in (root.txt) do echo "%%i">>rootfls.txt

with

for /f "tokens=* delims=" %%i in (root.txt) do echo "%%i">>rootfls.txt


Report Offensive Follow Up For Removal

Response Number 2
Name: masimar
Date: May 14, 2006 at 07:24:14 Pacific
Reply: (edit)

Same thing. The problem is that the line is reading fom two files. Because there are possibly multiple folders, it's reading from the list and doing a dir /b/a-d on each
directory.
for /f "tokens=* delims=" %%i in (directory.txt) do dir /b /a-d "%path%\%%i">>root%%i.txt

To keep them straight I name the new file contaning the file list from the variable %%i. To put quotes around the file names and keep them separate, I need a way to identify the variable, so I did

for /f "tokens=* delims=" %%i in (directory.txt) do for /f %%j in (root%%i.txt) do echo "%%j">>newroot%%i.txt

It works great except that %%j is only the first token so it leaves out everything past the first space.

Mark


Report Offensive Follow Up For Removal

Response Number 3
Name: IVO
Date: May 14, 2006 at 08:37:49 Pacific
Reply: (edit)

Actually I need to read again and again your post as I find it difficult to understand, but to be short and by help of my ESP power I suggest you replace now

for /f "tokens=* delims=" %%i in (directory.txt) do for /f %%j in (root%%i.txt) do echo "%%j">>newroot%%i.txt

with

for /f "tokens=* delims=" %%i in (directory.txt) do for /f "tokens=* delims=" %%j in (root%%i.txt) do echo "%%j">>newroot%%i.txt

If that doesn't work, post again and may be I'm ready to give you the answer (that exists, be sure).


Report Offensive Follow Up For Removal

Response Number 4
Name: masimar
Date: May 14, 2006 at 09:26:25 Pacific
Reply: (edit)

Well, you've got esp. That worked fine. I tried something along the same lines, but obviously got the syntax wrong.

It's hard for me to understand my own posts, and I know what I mean. I always thought I could convey a thought pretty concisely, but it's difficult sometimes.

But it's all good. I'm trying to learn. You've given me a piece of the puzzle that eluded me, and I thank you.

Mark


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Can't put quotes around files names

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge