Code archives/File Utilities/reformat path in dos 8.3 style

This code has been declared by its author to be Public Domain code.

Download source code

reformat path in dos 8.3 style by ford escort2002
dos .bat files can't reach the 'program files' folder for example , this function rename the long filename in the path with the "~1" stuff.
the function check if the final file is reachable or modify the "~1" in ~2 ~3 etc while it's reachable in case or some folder starts with the sames 6 ascii codes
Dim value(0)
;
;this function return a path in dos 8.3 format
;addin the unfamous ~1 stuff in the path
;
Function shorten$(pa$)
spat$=""
part$=""
For az=1 To Len(pa$)
	Select Mid$(pa$,az,1)
		Case "\"
			If Len(part$)>8
		
	part$=Left$(part$,6)+"~1"+"\"
			Else
				part$=part$+"\"	
			EndIf
			spat$=spat$+part$			
			part$=""
		Case "."
			If Len(part$)>8
				part$=Left$(part$,6)+"~1"+"."
			Else
				part$=part$+"."
			EndIf
			spat$=spat$+part$
			part$=""
		Default
			part$=part$+Mid$(pa$,az,1)
		End Select
Next
If Len(part$)>8
	part$=Left$(part$,6)+"~1"
EndIf
spat$=spat$+part$
If FileType(spat$)=0
For az=1 To Len(spat$)
	If Mid$(spat$,az,2)="~1"
		pos$=pos$+Chr$(az)
	EndIf
Next
Dim value(Len(pos$))
Repeat
value(0)=10
For va=1 To Len(pos$)
	If value(va-1)=10
		value(va)=value(va)+1
		value(va-1)=1
	EndIf
Next 
For ch=1 To Len(pos$)
di$=Left$(spat$,Asc(Mid$(pos$,ch,1))-1)+"~"+Str$(value(ch))+"\"+Right$(spat$,Len(spat$)-(Asc(Mid$(pos$,2,1))+2))
Print di$
Next 
Until FileType(di$)<>0
Return di$
EndIf
Return spat$
End Function

Comments

None.

Code Archives Forum