Results 1 to 3 of 3

Thread: [RESOLVED] Simple - Create txt file

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Resolved [RESOLVED] Simple - Create txt file

    Guys,

    How do I create a blank text file if it doesn't exist....

    Bob

    VB Code:
    1. 'Setup CustomDic for C1Spell
    2.         Dim CDFile As String
    3.         CDFile = CurrentContract.Path & PWBlib.library.DynamicProperty("CustomDicLocation")
    4.         If Not IO.File.Exists(CDFile) Then
    5.             'IO.FileMode.CreateNew
    6.         End If
    7.         SpellInitialised = True
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Simple - Create txt file

    IO.File.CreateText("c:\myfile.txt")

    From Documentation on IO.File.CreateText:
    This method is equivalent to StreamWriter(String, Boolean) with the append parameter set to false. If the file specified by path does not exist, it is created. If the file does exist, its contents are overwritten. Additional threads are permitted to read the file while it is open.
    Meaning that you don't have to check if it doesnt exist. If it doesnt exist, it creates it.... if you don't want to overwrite the contents if it exists, just use IO.File.AppendText...

    Documentation on IO.File.AppendText:
    This method is equivalent to StreamWriter(String, Boolean). If the file specified by path does not exist, it is created. If the file does exist, write operations to the StreamWriter append text to the file. Additional threads are permitted to read the file while it is open.
    So with appendtext, you still don't have to check if it exists, and also you won't overwrite the current contents of the file...
    Last edited by gigemboy; Mar 10th, 2006 at 05:49 AM.

  3. #3

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: Simple - Create txt file

    Thanks Gig.

    Bob
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width