filename in 8.3 format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The filesystemobject file object had a shortname property which was the
filename in 8.3 format. I have not been able to locate in system.io an
equivalent property. Is there an equivalent in system.io or do I need to
stick with the filesystemobject in order to have access to this property?
 
The filesystemobject file object had a shortname property which was the
filename in 8.3 format. I have not been able to locate in system.io an
equivalent property. Is there an equivalent in system.io or do I need to
stick with the filesystemobject in order to have access to this property?

I don't know of anyway - except via P/Invoke to the GetShortPathName api...
Here is a simplfied example:

Option Strict On
Option Explicit On

Imports System

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(0, 0)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(288, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Const MAX_PATH As Integer = 260

Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As System.Text.StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim path As String =
Environment.GetFolderPath(Environment.SpecialFolder.Personal)

Dim buffer As New System.Text.StringBuilder(MAX_PATH)
GetShortPathName(path, buffer, buffer.Capacity)
TextBox1.Text = buffer.ToString()
End Sub
End Class
 
Thanks for the reply but it looks like it may be simpler and just as clean to
add a reference to scrrun.dll and use the filesystemobject if I want 8.3
filenames.

Regards,
Erik
 
Thanks for the reply but it looks like it may be simpler and just as clean to
add a reference to scrrun.dll and use the filesystemobject if I want 8.3
filenames.

Regards,
Erik

Huh? I showed an example of using this api. It is a very simple
matter. Believe me, referencing scrrun.dll is a bad idea if you can get
around it.
 
:

[snip] Believe me, referencing scrrun.dll is a bad idea if you can get
around it.

Didn't mean to "dis" your reply. I was not familiar with the
GetShortPathName api so perhaps it was my familiarity with the
filesystemobject that made me call it simpler. You are correct
GetShorPathName is very simple.

I do wonder however, what makes referencing scrrun.dll such a bad idea?

Wouldn't referencing the properties of a filesystemobject.file object be
quicker processing timewise than calling a function against a system.io.file
instance?

Regards
Erik

Erik,

Referencing scrrun.dll is a bad idea for several reasons (in no particular
order)...

1. Performance. To use objects from scrrun.dll, you are crossing over into
the land of COM interop - which is very expensive, even compared to
P/Invoke (which is also expensive, but as bad as COM interop)

2. What do you do on a system that has disabled wsh?

3. There have been dll hell issues associated with wsh and scrrun.dll in
the past.

Overall - using System.IO.File is going to be much faster then using
FileSystemObjects from scrrun.dll. Basically, except for COM interop - it
is the same reasons not to use them in VB6. The code may look a little
cleaner - but it is probably half as fast as using the VB6 native IO.
 
Tom Shelton said:
2. What do you do on a system that has disabled wsh?

LaserFiche is a document imaging system that has an import list feature. I
am writing an automated import list generator. Although LaserFiche itself
does not have any problem with long paths and filenames, the import list
feature still requires the 8.3 pathnames and filenames.
I expect LaserFiche will upgrade the import list feature ... eventually:-)
I am converting my vb6 code which used the filesystemobject to .NET and I
don't want to take my code down a deadend development path.
I'll definately use the api call instead of the scrrun.dll.

Regards,
Erik
 
Back
Top