עבור לתוכן

שאלה ב-VB סקריפט.

Featured Replies

פורסם

אהלן,

אני צריך לכתוב ב-VB סקריפט, אפשר להגדיר את זה כ-PRE PROCESS, שאני מקבל קובץ כלשהו, אחרי 79 שורות אני צריך לכתוב לשם ASCII CODE של שבירת עמוד (יש לי את ה-ASCII CODE). האם למישהו יש המלצה מאיפה להתחיל?

פורסם

העבודה עם קבצים בVBSCRIPT די מסורבלת בגלל שיש רק שלושה מצבי עבודה, או קריאה בלבד, או כתיבה שאז כל הקובץ נמחק ונוצר מחדש, או append המאפשר כתיבה לסוף הקובץ.

לכן מה שאני בד"כ עושה הוא קורא את כל הקובץ לתוך משתנה, חותך אותו למערך ע"י split, משנה את השורה שאני רוצה, ומחבר חזרה ע"י join.

Const ForWriting = 2, ForReading = 1, FormatUnicoe = -1, FormatASCII = 0

'path for your file
strFilePath = "C:\Documents and Settings\Administrator\Desktop\example.txt"

'ascii code
intASCIICode = 12

'create file system object and open text file for reading.
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFileSystem.OpenTextFile(strFilePath, ForReading, false, FormatASCII)

'read content and close stream
strContent = objTextStream.ReadAll
objTextStream.close

'split content to array, each array element will hold 1 line
arrContent = Split(strContent, Chr(13) & Chr(10))
'edit the begining of line 80
arrContent(79) = Chr(intASCIICode) & arrContent(79)
'join array again
strContent = Join(arrContent, Chr(13) & Chr(10))

'open file for writing and write the content and close stream
Set objTextStream = objFileSystem.OpenTextFile(strFilePath, ForWriting, false, FormatASCII)
objTextStream.Write(strContent)
objTextStream.close

זהו פחות או יותר..

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים