<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Добавление текста в файл без дублирования]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5913&amp;type=atom" />
	<updated>2011-06-17T09:00:40Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=5913</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Добавление текста в файл без дублирования]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=49167#p49167" />
			<content type="html"><![CDATA[<p>VSVLAD огромное при огромное спасибо<br />вы меня спасли !!!! </p><p>все работает еще раз спасибочки <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Елена А]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27025</uri>
			</author>
			<updated>2011-06-17T09:00:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=49167#p49167</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Добавление текста в файл без дублирования]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=49166#p49166" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>Option Explicit

Dim oFSO, oTS, sFileText
Dim sDataToAdd, sBuff

Const vbForReading = 1
Const vbForWriting = 2

sDataToAdd = &quot;sssP10 2011/str&quot; &amp; vbCrLf &amp; _
			 &quot;sssP11 2011/str&quot; &amp; vbCrLf

If WScript.Arguments.Count = 0 Then
	MsgBox &quot;Необходимо передать файл в параметре&quot;, vbExclamation
	WScript.Quit 1
End If

Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set oTS = oFSO.OpenTextFile(WScript.Arguments(0), vbForReading)

sFileText = oTS.ReadAll
oTS.Close

If Len(sFileText) &gt;= Len(sDataToAdd) Then
	sBuff = Right(sFileText, Len(sDataToAdd))
	If LCase(sBuff) = LCase(sDataToAdd) Then
		MsgBox &quot;Данные уже были добавлены&quot;, vbInformation
		WScript.Quit 2
	End If
End If

sFileText = sFileText &amp; sDataToAdd

Set oTS = oFSO.OpenTextFile(WScript.Arguments(0), vbForWriting)
oTS.Write(sFileText)
oTS.Close

Set oTS = Nothing
Set oFSO = Nothing

WScript.Quit 0</code></pre></div>]]></content>
			<author>
				<name><![CDATA[VSVLAD]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24998</uri>
			</author>
			<updated>2011-06-17T08:55:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=49166#p49166</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Добавление текста в файл без дублирования]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=49164#p49164" />
			<content type="html"><![CDATA[<p>не совсем поняла как адаптировать этот код под мои нужды но все ровно большое спасибо , буду пробовать.</p>]]></content>
			<author>
				<name><![CDATA[Елена А]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27025</uri>
			</author>
			<updated>2011-06-17T07:28:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=49164#p49164</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Добавление текста в файл без дублирования]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=49163#p49163" />
			<content type="html"><![CDATA[<p>Вот пример, содержащий необходимый код.<br /></p><div class="codebox"><pre><code>&#039;Created by OldBoa
Option Explicit
Dim WshShell,WshNetwork,Username,oDrives,i,Paths,objFSO,File,logfile,Match,TextStream,Str
Set WshShell = CreateObject(&quot;WScript.Shell&quot;)
Set objFSO=CreateObject(&quot;Scripting.FileSystemObject&quot;)
Username = WshShell.ExpandEnvironmentStrings(&quot;%USERNAME%&quot;)
File = &quot;\\server\share$\NetPath\&quot; &amp; Username &amp; &quot;.txt&quot;
Set WshNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)
Set oDrives = WshNetwork.EnumNetworkDrives
Paths = &quot;&quot;
If objFSO.FileExists(File) then
    Set logfile = objFSO.getfile(File)
    For i = 0 to oDrives.Count - 1 Step 2
        Match = 0
        Set TextStream = logfile.OpenAsTextStream(1)
        While Not TextStream.AtEndOfStream
            Str = TextStream.ReadLine()
            If Str = oDrives.Item(i+1) Then
                Match = 1
            End If
        Wend
        If Not Match = 1 Then
            Paths = Paths &amp; oDrives.Item(i+1) &amp; vbCrLf
        End If
    Next
    TextStream.Close
    Set TextStream = logfile.OpenAsTextStream(8)
Else
    Set TextStream = objFSO.CreateTextFile(File)
    For i = 0 to oDrives.Count - 1 Step 2
        Paths = Paths &amp; oDrives.Item(i+1) &amp; vbCrLf
    Next
End If
If Not Paths = &quot;&quot; Then
    TextStream.WriteLine Paths
End If
TextStream.Close</code></pre></div><p>Хотя тут для сравнения двух строк лучше будет использовать StrComp. Т.е. вместо строки </p><div class="codebox"><pre><code>If Str = oDrives.Item(i+1) Then</code></pre></div><p>написать </p><div class="codebox"><pre><code>If StrComp(Str, oDrives.Item(i+1)) = 0 Then</code></pre></div>]]></content>
			<author>
				<name><![CDATA[OldBoa]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25478</uri>
			</author>
			<updated>2011-06-17T05:13:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=49163#p49163</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Добавление текста в файл без дублирования]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=49161#p49161" />
			<content type="html"><![CDATA[<p>Добрый день !<br />необходимо добавить две строчки в файл но перед добавлением проверить нет ли их в нем что бы не было дублирования&nbsp; <br />файл C:\test\test.txt<br />c содержимым:<br />pppP1&nbsp; &nbsp; 2010/str<br />pppP2&nbsp; &nbsp;2010/str<br />pppP3&nbsp; &nbsp;2010/str<br />в конце пустая строка</p><p>нужно добавить две строчки в конец файла<br />sssP10 2011/str<br />sssP11 2011/str<br />и сохранить пустую строчку в конце файла</p><p>Сделать нужно очень, очень срочно<br />помогите пожалуйста <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Елена А]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27025</uri>
			</author>
			<updated>2011-06-17T03:17:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=49161#p49161</id>
		</entry>
</feed>
