-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdos83.py
More file actions
executable file
·59 lines (55 loc) · 2.73 KB
/
Copy pathdos83.py
File metadata and controls
executable file
·59 lines (55 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
__version__ = "$Revision: 29 $, $Date: 2006-07-24 17:41:36 +0200 (ma, 24 jul 2006) $, $Author: quintijn $"
#probably not used anymore (Quintijn)
import string
import os.path
def convertTo83Path(fullPath,removeSpacesOnly=0):
"""tries to convert (valid) long path names to Dos83 pathnames
"""
if fullPath.find('-') >= 0:
print 'found "-", dos83 ignore: %s'% fullPath
return fullPath
# only possible if fullPath exists.
# no garantee that the converted path refers to the same location
# I have not found standard functions for this conversion,
# nor do I know how to compare equivalence: os.path.samefile is not available in Win
# Are there any winApi calls?
if not os.path.exists(fullPath):
print 'Path conversion failed. This is not a valid path:'
print fullPath
return ''
# go try convert
(name,ext)=os.path.splitext (fullPath)
splitPath=string.split(name,'\\')
splitPath83=splitPath[:]
for subPath in splitPath:
concatPath=string.join(string.split(subPath),'')
if (concatPath<>subPath) or ((not removeSpacesOnly) and (len(subPath)>8)):
# convert subpath to Dos 8.3 convention
concatPath=concatPath[0:min(6,len(concatPath))]
i=splitPath.index(subPath)
altConcatPath=[]
for n in range(1,10): # try simple rule and find those that exist
splitPath83[i]=concatPath+'~'+str(n)
Path83=string.join(splitPath83,'\\')+ext
if os.path.exists(Path83):
if os.stat(Path83)==os.stat(fullPath):
altConcatPath.append(concatPath+'~'+str(n))
# how many existing with matching stats did we find?
if len(altConcatPath)==1:
splitPath83[i]=altConcatPath[0]
elif len(altConcatPath)>1:
splitPath83[i]=altConcatPath[0]
print 'Warning. Non unique Path conversion.'
else:
splitPath83[i]=concatPath+'??'
print 'Warning. Insufficient rule for conversion.'
Path83=string.join(splitPath83,'\\')+ext
if not os.path.exists(Path83):
print 'Path conversion failed. This is not a valid Dos 8.3 path:'
print Path83
return ''
else:
return Path83
def convertSpacedSubPaths(fullPath):
return convertTo83Path(fullPath,removeSpacesOnly=1)
print convertTo83Path('C:\Program Files')#print convertTo83Path('C:\Program Files\Common Files\Microsoft Shared\MSCREATE.DIR')#print convertTo83Path('C:\Program Files\ArrayVisualizer\SAMPLES\SAMPLES.HTM')#print convertSpacedSubPaths('C:\Program Files\ArrayVisualizer\SAMPLES\SAMPLES.HTM')