double backslashes 
Author Message
 double backslashes

Hello, how could I take this:

C:\WINNT\System32\services.exe

And make it this:

C:\\WINNT\\System32\\services.exe

with VBScript?  Would it be best to use regexp?   Below is a sampling of a
text file that I would want to run through a script that would double all of
the backslashes.

C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe
C:\Program Files\Adobe\Acrobat 5.0\Distillr\Acrodist.exe
c:\program files\adobe\acrobat 5.0\Reader\AcroRd32.exe
C:\Program Files\Netscape\Communicator\Program\AIM\aim.exe
C:\Program Files\Symantec\pcAnywhere\AWHOST32.EXE
C:\Program Files\Symantec\pcAnywhere\Awras32.exe
C:\Program Files\Symantec\pcAnywhere\awrem32.exe
C:\Program Files\Chapura\Conduit Manager\CCMgr.exe
C:\Program Files\NetMeetingNT\conf.exe
C:\Program Files\Compaq\Compaq Management Agents\cpqalert.exe
C:\WINNT\cpqdiag\cpqdiag.exe
C:\Program Files\Compaq\Compaq PnP Manager\cpqpnpmgr.exe
C:\Program Files\IBM\Client Access\cwb3uic.exe

I think this is how I would start the script:

Dim objFS, inFile, outfile

On error resume next

Const CreateIfNotExist = True
Const ForReading = 1
Set objFS = CreateObject("scripting.FileSystemObject")
set inFile = objFS.opentextfile ("c:\miffed\remsinv\appPaths.txt",
ForReading, CreateIfNotExist, TristateFalse)
Set outFile = objFS.CreateTextFile ("c:\miffed\remsinv\appPaths2.txt", True)

Please advise if I should use regexp and if I seem to be missing anything,
thanks in advance for any help!



Mon, 10 Oct 2005 02:37:10 GMT  
 double backslashes

Quote:

> Hello, how could I take this:
> C:\WINNT\System32\services.exe

> And make it this:
> C:\\WINNT\\System32\\services.exe

> with vbscript?  Would it be best to use regexp?

I would have used the Replace function (see below).

Quote:
> (snip)
> I think this is how I would start the script:

> Dim objFS, inFile, outfile

> On error resume next

> Const CreateIfNotExist = True
> Const ForReading = 1
> Set objFS = CreateObject("scripting.FileSystemObject")
> set inFile = objFS.opentextfile ("c:\miffed\remsinv\appPaths.txt",
> ForReading, CreateIfNotExist, TristateFalse)
> Set outFile = objFS.CreateTextFile ("c:\miffed\remsinv\appPaths2.txt", True)

Some comments:

(1) You should never use "On error resume next" unless you *really* need it (and
for this script you don't). It makes error debugging so much harder.

(2) You need to define TristateFalse, it does not come defined with VBScript
(only the vbSomething does).

This should work:

Dim objFS, inFile, outfile, sAllText

Const TristateFalse = 0
Const CreateIfNotExist = True
Const ForReading = 1

Set objFS = CreateObject("scripting.FileSystemObject")
Set inFile = objFS.opentextfile ("c:\miffed\remsinv\appPaths.txt", _
      ForReading, CreateIfNotExist, TristateFalse)

sAllText = inFile.Readall
inFile.Close
sAllText = Replace(sAllText, "\", "\\")

Set outFile = objFS.CreateTextFile ("c:\miffed\remsinv\appPaths2.txt", True)
outFile.Write sAllText
outFile.Close

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Mon, 10 Oct 2005 03:27:05 GMT  
 double backslashes
Wow, that was alot simpler than I thought!  Worked like a charm.  I'm glad I
asked, and fortunate that a helpful pro like yourself answered.  Thanks!



Quote:

> > Hello, how could I take this:
> > C:\WINNT\System32\services.exe

> > And make it this:
> > C:\\WINNT\\System32\\services.exe

> > with vbscript?  Would it be best to use regexp?

> I would have used the Replace function (see below).

> > (snip)
> > I think this is how I would start the script:

> > Dim objFS, inFile, outfile

> > On error resume next

> > Const CreateIfNotExist = True
> > Const ForReading = 1
> > Set objFS = CreateObject("scripting.FileSystemObject")
> > set inFile = objFS.opentextfile ("c:\miffed\remsinv\appPaths.txt",
> > ForReading, CreateIfNotExist, TristateFalse)
> > Set outFile = objFS.CreateTextFile ("c:\miffed\remsinv\appPaths2.txt",
True)

> Some comments:

> (1) You should never use "On error resume next" unless you *really* need
it (and
> for this script you don't). It makes error debugging so much harder.

> (2) You need to define TristateFalse, it does not come defined with
VBScript
> (only the vbSomething does).

> This should work:

> Dim objFS, inFile, outfile, sAllText

> Const TristateFalse = 0
> Const CreateIfNotExist = True
> Const ForReading = 1

> Set objFS = CreateObject("scripting.FileSystemObject")
> Set inFile = objFS.opentextfile ("c:\miffed\remsinv\appPaths.txt", _
>       ForReading, CreateIfNotExist, TristateFalse)

> sAllText = inFile.Readall
> inFile.Close
> sAllText = Replace(sAllText, "\", "\\")

> Set outFile = objFS.CreateTextFile ("c:\miffed\remsinv\appPaths2.txt",
True)
> outFile.Write sAllText
> outFile.Close

> --
> torgeir
> Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of the 1328 page
> Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Mon, 10 Oct 2005 04:51:51 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Make GSView select double-sided print to double-sided printer

2. Double Sided Printing On Double Sided Printer, How ?

3. Win32 GetDriveType returns erroneous info if backslash omitted from drive argument

4. Getting Trailing Backslash for Special Folders

5. converting string containing binary double to double

6. QBasic MBF Double Conversion to VB6 Floating Point Double

7. Stop backslash behaving as the escape character

8. Backslash disapears

9. getting to read the backslash

10. Backslash problems - help!

11. How to print backslash?

12. Reading registry values containing a backslash (\)

 

 
Powered by phpBB® Forum Software