VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts a path and/or a filename into something DOS can read, contains two subs.

by Emporer (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 9th November 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts a path and/or a filename into something DOS can read, contains two subs.

API Declarations


The only flaw that I know of is in these are the use of folders with periods in the name, DOS reads those different.

Rate Converts a path and/or a filename into something DOS can read, contains two subs.



Public Function DosFilename(Filename) As String
  Dim ss(1 To 40) As String
  st = 1
  c = 0
  i = 0
  Index = 1
  Dim spcFound As Boolean
  fname = Left(Filename, Len(Filename) - 4)
  Fext = Right(Filename, 4)
  Do
    i = i + 1
    c = c + 1
    ss(Index) = Mid(fname, st, i)
    If (Right(ss(Index), 1) = " ") Then
       ss(Index) = Left(ss(Index), Len(ss(Index)) - 1)
       st = st + i
       i = 0
       spcFound = True
       Index = Index + 1
    End If
    If (c >= Len(fname)) Then Exit Do
    DoEvents
  Loop
  fname = ""
  For i = 1 To Index
   fname = fname & ss(i)
  Next i
  If (Len(fname) > 8) Or spcFound Then
     DosFilename = Left(fname, 6) & "~1" & Fext
  Else
     DosFilename = Filename
  End If
End Function

Public Function DosPath(Path) As String
  Dim Dr(1 To 50) As String
  Dim SpcFnd As Boolean
  D = Left(Path, 3)
  K = RTrim(Mid(Path, 4, Len(Path)))
  Do While K <> ""
    i = i + 1
    For n = 1 To Len(K)
      s1 = ""
      Dr(i) = Dr(i) & Mid(K, n, 1)
      If (Right(Dr(i), 1) = "\") Then Exit For
    Next n
    K = RTrim(Mid(K, n + 1, Len(K)))
    If (Right(Dr(i), 1) = "\") Then Dr(i) = Left(Dr(i), Len(Dr(i)) - 1)
    If (Len(Dr(i)) > 8) Then
       For x = 1 To Len(Dr(i))
          s1 = s1 & Mid(Dr(i), x, 1)
          If (Right(s1, 1) = " ") Then s1 = Left(s1, Len(s1) - 1)
       Next x
       Dr(i) = Left(s1, 6) & "~1"
    Else
       For x = 1 To Len(Dr(i))
          s1 = s1 & Mid(Dr(i), x, 1)
          If (Right(s1, 1) = " ") Then SpcFnd = True: s1 = Left(s1, Len(s1) - 1)
       Next x
       If SpcFnd Then
         If (Len(s1) > 6) Then
            Dr(i) = Left(s1, 6) & "~1"
         Else
            Dr(i) = s1 & "~1"
         End If
       End If
    End If
    If (K = "\") Or (K = "") Then Exit Do
    DoEvents
  Loop
  DosPath = D
  For i2 = 1 To i
    DosPath = DosPath & Dr(i2) & "\"
  Next i2
End Function

Download this snippet    Add to My Saved Code

Converts a path and/or a filename into something DOS can read, contains two subs. Comments

No comments have been posted about Converts a path and/or a filename into something DOS can read, contains two subs.. Why not be the first to post a comment about Converts a path and/or a filename into something DOS can read, contains two subs..

Post your comment

Subject:
Message:
0/1000 characters