1.

Solve : Batch file for Text File Read "surround" and Write?

Answer»

I have some simple text files that contain the file paths for folders and sub folders.  My current batch file creates the folder with a list of the file paths.  This is the command I am using to make the files:

     dir /ad /s /b >> New_File.txt

What I get written to the file (say I ran this from My Documents) is similar to the following:

     C:\Documents and Setting\Administrator\My Documents\My Pictures
     C:\Documents and Setting\Administrator\My Documents\My Videos
     C:\Documents and Setting\Administrator\My Documents\My Music

What I need to do now is to be able to read this file one line at a time and put each line in " " so as to look like the following:

     "C:\Documents and Setting\Administrator\My Documents\My Pictures"
     "C:\Documents and Setting\Administrator\My Documents\My Videos"
     "C:\Documents and Setting\Administrator\My Documents\My Music"

The program that takes this file as an input can be particular about how it takes in a list of paths.  I can do this in VBA, however, I would rather not use excell for a rather simple operation if at all possible.

Thanks for the help.

Try this:

Code: [Select]ECHO off
cls

for /f "Delims=" %%a in (New_File.txt) do (
    echo "%%a" >> New_File1.txt
)

New_File1.txt should contain

"C:\Documents and Setting\Administrator\My Documents\My Pictures"
"C:\Documents and Setting\Administrator\My Documents\My Videos"
"C:\Documents and Setting\Administrator\My Documents\My Music"

Good LUCK. Quote from: Dusty on November 20, 2008, 07:40:20 PM

Try this:

Code: [Select]echo off
cls

for /f "Delims=" %%a in (New_File.txt) do (
    echo "%%a" >> New_File1.txt
)

New_File1.txt should contain

"C:\Documents and Setting\Administrator\My Documents\My Pictures"
"C:\Documents and Setting\Administrator\My Documents\My Videos"
"C:\Documents and Setting\Administrator\My Documents\My Music"

Good luck.

Dusty,

Thank you, that works perfectly!    I am only going to add a few things so as to create a temp file that can be deleted and to create a new file each time.  This is to create a Search.pro file for ProEngineer so that it can find exactly where it needs to look for all of the parts of an assembly each time AUTOMATICALLY when a file is opened.  It'll save a lot of time for people importing new assemblies to their computer so that they can keep their standard Config.pro file and simply create new search.pro files when they open an assembly.  Long story with the ProEngineer side of things, but needless to say this will make my life a lot easier.

Thanks again for your help!
SEBNN

Oh, and so someone can see what the code looks like, it is below.

Code: [Select]echo !TrialFile >TrialFile.txt
dir /ad /s /b >>TrialFile.tmp
echo off
cls

for /f "Delims=" %%a in (TrialFile.tmp) do (
echo "%%a" >>TrialFile.txt
)
del .\TrialFile.tmp

Like I said, it works great and I have tested it multiple times.  Also, as an explanation, the ! in the code is to indicate to ProEngineer that the CHARACTERS following it are a comment and to write SOMETHING other than a blank line when the file is cleared for the first run.Thanks for coming back to report your success and post your coding.

D.



Discussion

No Comment Found