# VB:save without an extension



## flytape8490 (Oct 7, 2003)

2 things. 
1:I'm writing a program in VB that compiles data into a file in this format (qotes needed):
"isbn", "ttl.text","aut.text","loc.text","cwd.text" to the extension stored in string isbnp

2: The file i want to write it to has no extension. If you don't know what I mean, goto start>run> "Edit C:\noext" and then save when the window pops up. Gointo drive C and the look at noext. That's what i'm trying to make. The path wold look something like this "/0/9/8" where 8 would be my extensionless file.


so how would I do this?


----------



## flytape8490 (Oct 7, 2003)

oh, and before It saves- it needs to check if the directory stored in isbnp exists, and if not to create the directory.


----------



## flytape8490 (Oct 7, 2003)

still nothing? wow.


----------



## coderitr (Oct 12, 2003)

When I do what you suggested (Start / Run / Edit C:\noext / Save ) I get a file in the root of C: with no extension. I'm not sure what you mean with the /0/9/8 thing. Post your code and I'll see if I can help but you should be able to save a file with no extension just by not including an extension in the code.

Exception: sometimes Windows adds an extension on its own if the option to "Hide extensions for known file types" is selected. I know that Notepad does this.


----------



## coderitr (Oct 12, 2003)

To check for the existence of the directory, you'll have to parse the file name and just do a mkdir on the directory name. Ignore the error that occurs if the directory already exists.


----------



## flytape8490 (Oct 7, 2003)

by 0/9/8 i mean that 0/9/ 'd be the directory i'm checking for (if non existant, to create), and 8 is the extensionless file.

As for parsing a filename and mkdir... what?


----------



## flytape8490 (Oct 7, 2003)

bump


----------



## coderitr (Oct 12, 2003)

flytape8490 said:


> by 0/9/8 i mean that 0/9/ 'd be the directory i'm checking for (if non existant, to create), and 8 is the extensionless file.


The directory name is "0" ? Odd, but okay. The forward slash ( / ) is meaningless in Windows except as command line parameter delimiters. Path components are separated by the backslash ( \ ) . So you're creating a file called 8 in a directory called 0\9 ? Again, if that's what you want then fine but it's a little odd if you ask me. File and directory names should be descriptive so someone coming behind you doesn't have to read your code to find out what's in it.


flytape8490 said:


> As for parsing a filename and mkdir... what?


You have a file name like c:\windows\win.ini -- parsing the file name means separating it into its components. In my example, the path is c:\windows and the file name is win.ini. If you want to make sure a directory exists before you attempt to write a file to it, then you're going to have to parse the file name to get the path and create the directory (mkdir = make directory.) The create directory call will generate an error if the directory already exists but you can trap that error and ignore it.


----------



## flytape8490 (Oct 7, 2003)

Mk, so the mkdir is programed and working, but now how do I make my extensionless file?
The name of the extless file would be stored in the textbox variable ibn4.text.
In this file, i need to have the information

"isbn", "ttl.text", "aut.text" , "loc.text", "cwd.text"

Where isbn, ttl.text, aut.text, loc.text, and cwd.text would be replaced by the data each of these variables store. I would also need the "s and the ,s there.

So after all the data is entered and the save procvess is finished, the data in the blank file would look something like
"058967", "bla","bla","bla","bla"


----------



## coderitr (Oct 12, 2003)

So the values stored in your form entry fields (isbn, title, author, location, cwd) need to be saved in a file? Just open the file and write to it. There is no difference between opening a file with an extension and without. In VB


```
Open filename For Output as #1
Print #1, isbn, & "," & ttl.text & "," & aut.text & "," & loc.text & "," & cwd.text
Close #1
```


----------



## flytape8490 (Oct 7, 2003)

So, here i have the code you give me, tweaked to rid myself of as many errors as i can.


```
[B]Open[/B](isbnp & ibn4.Text, [U]For[/U] Output as #1)
          Print(1, isbn & "," & ttl.Text & "," & aut.Text & "," & loc.Text & "," & cwd.Text)
          Close [COLOR="blue"]#[/COLOR]1
```
I received no errors before I had put the tweaked code in, but after I received the following.

*'Open' is not declared. File I/O functionality is available in the 'Microsoft.VisualBasic' namespace.*
Expression expected.
Expression expected.
Method arguments must be enclosed in parentheses.
Also, note that the string variable "isbnp" contains the path into our extensionless is to be saved ("A:\" & ibn1.text & "\" & ibn2.text & "\" & ibn.text & "\"), and the data in "ibn4.text" is the name of our extensionless.


----------



## flytape8490 (Oct 7, 2003)

oh, here's my whole program, bytheway. (probably should've done this at the beginning, but ohwell.)


```
Public Class Form1
Dim isbn As String
Dim isbnp As String

   Private Sub btn(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mbk.Click
      If ibn1.Text = "" Or ibn2.Text = "" Or ibn3.Text = "" Or ibn4.Text = "" Or ttl.Text = "" Or aut.Text = ""  
                        Or pub.Text = "" Then MsgBox("Some fields are blank- fix them or die!") Else a()
   End Sub

   Function a()
      isbn = (ibn1.Text & "-" & ibn2.Text & "-" & ibn3.Text & "-" & ibn4.Text)
      isbnp = ("A:\" & ibn1.Text & "\" & ibn2.Text & "\" & ibn3.Text & "\")
      If loc.Text = "" Then loc.Text = ("Unavailable")
      If cwd.Text = "" Then cwd.Text = ("Unavailable")
       Try
        MkDir(isbnp)
        b()
        ibn1.Text = ""
        ibn2.Text = ""
        ibn3.Text = ""
        ibn4.Text = ""
        ttl.Text = ""
        aut.Text = ""
        pub.Text = ""
        loc.Text = ""
        cwd.Text = ""
       Catch ex As Exception
        MsgBox("This ISBN directory already exists.")
       End Try
   End Function

   Function b()
      Open(isbnp & ibn4.Text, For Output as #1)
         Print(1, isbn & "," & ttl.Text & "," & aut.Text & "," & loc.Text & "," & cwd.Text)
         Close #1
    End Function

End Class
```
FYI:the if statement towards the beginning isn't really split

My form contains...
Textboxes ibn(1/2/3/4), ttl, aut, pub, loc, and cwd. Also, there is button btn.


----------



## flytape8490 (Oct 7, 2003)

bump


----------



## flytape8490 (Oct 7, 2003)

...bumpitybumpbump, bumpitybumpbump... i think i'm being ignored...


----------



## coderitr (Oct 12, 2003)

I didn't know you are using VB.Net. I'm sorry but I can't be any more help.


----------



## flytape8490 (Oct 7, 2003)

I'm using .net? I thought it was express...


----------



## coderitr (Oct 12, 2003)

Express is .NET


----------



## flytape8490 (Oct 7, 2003)

>_<


----------

