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 Wrapper for shlwapi.dll in ctypes.
30 """
31
32 __revision__ = "$Id: shlwapi.py 618 2010-02-11 02:15:09Z qvasimodo $"
33
34 from defines import *
35
36 OS_WINDOWS = 0
37 OS_NT = 1
38 OS_WIN95ORGREATER = 2
39 OS_NT4ORGREATER = 3
40 OS_WIN98ORGREATER = 5
41 OS_WIN98_GOLD = 6
42 OS_WIN2000ORGREATER = 7
43 OS_WIN2000PRO = 8
44 OS_WIN2000SERVER = 9
45 OS_WIN2000ADVSERVER = 10
46 OS_WIN2000DATACENTER = 11
47 OS_WIN2000TERMINAL = 12
48 OS_EMBEDDED = 13
49 OS_TERMINALCLIENT = 14
50 OS_TERMINALREMOTEADMIN = 15
51 OS_WIN95_GOLD = 16
52 OS_MEORGREATER = 17
53 OS_XPORGREATER = 18
54 OS_HOME = 19
55 OS_PROFESSIONAL = 20
56 OS_DATACENTER = 21
57 OS_ADVSERVER = 22
58 OS_SERVER = 23
59 OS_TERMINALSERVER = 24
60 OS_PERSONALTERMINALSERVER = 25
61 OS_FASTUSERSWITCHING = 26
62 OS_WELCOMELOGONUI = 27
63 OS_DOMAINMEMBER = 28
64 OS_ANYSERVER = 29
65 OS_WOW6432 = 30
66 OS_WEBSERVER = 31
67 OS_SMALLBUSINESSSERVER = 32
68 OS_TABLETPC = 33
69 OS_SERVERADMINUI = 34
70 OS_MEDIACENTER = 35
71 OS_APPLIANCE = 36
72
73
74
75
76
77
93
94
95
96
98 _PathAddBackslashA = windll.shlwapi.PathAddBackslashA
99 _PathAddBackslashA.argtypes = [LPSTR]
100 _PathAddBackslashA.restype = LPSTR
101
102 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)
103 retval = _PathAddBackslashA(lpszPath)
104 if retval == NULL:
105 raise ctypes.WinError()
106 return lpszPath.value
107
109 _PathAddBackslashW = windll.shlwapi.PathAddBackslashW
110 _PathAddBackslashW.argtypes = [LPWSTR]
111 _PathAddBackslashW.restype = LPWSTR
112
113 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)
114 retval = _PathAddBackslashW(lpszPath)
115 if retval == NULL:
116 raise ctypes.WinError()
117 return lpszPath.value
118
119 PathAddBackslash = GuessStringType(PathAddBackslashA, PathAddBackslashW)
120
121
122
123
124
126 _PathAddExtensionA = windll.shlwapi.PathAddExtensionA
127 _PathAddExtensionA.argtypes = [LPSTR, LPSTR]
128 _PathAddExtensionA.restype = bool
129 _PathAddExtensionA.errcheck = RaiseIfZero
130
131 if not pszExtension:
132 pszExtension = None
133 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)
134 _PathAddExtensionA(lpszPath, pszExtension)
135 return lpszPath.value
136
138 _PathAddExtensionW = windll.shlwapi.PathAddExtensionW
139 _PathAddExtensionW.argtypes = [LPWSTR, LPWSTR]
140 _PathAddExtensionW.restype = bool
141 _PathAddExtensionW.errcheck = RaiseIfZero
142
143 if not pszExtension:
144 pszExtension = None
145 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)
146 _PathAddExtensionW(lpszPath, pszExtension)
147 return lpszPath.value
148
149 PathAddExtension = GuessStringType(PathAddExtensionA, PathAddExtensionW)
150
151
152
153
154
156 _PathAppendA = windll.shlwapi.PathAppendA
157 _PathAppendA.argtypes = [LPSTR, LPSTR]
158 _PathAppendA.restype = bool
159 _PathAppendA.errcheck = RaiseIfZero
160
161 if not pszMore:
162 pszMore = None
163 lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH)
164 _PathAppendA(lpszPath, pszMore)
165 return lpszPath.value
166
168 _PathAppendW = windll.shlwapi.PathAppendW
169 _PathAppendW.argtypes = [LPWSTR, LPWSTR]
170 _PathAppendW.restype = bool
171 _PathAppendW.errcheck = RaiseIfZero
172
173 if not pszMore:
174 pszMore = None
175 lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH)
176 _PathAppendW(lpszPath, pszMore)
177 return lpszPath.value
178
179 PathAppend = GuessStringType(PathAppendA, PathAppendW)
180
181
182
183
184
185
187 _PathCombineA = windll.shlwapi.PathCombineA
188 _PathCombineA.argtypes = [LPSTR, LPSTR, LPSTR]
189 _PathCombineA.restype = LPSTR
190
191 lpszDest = ctypes.create_string_buffer("", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1))
192 retval = _PathCombineA(lpszDest, lpszDir, lpszFile)
193 if retval == NULL:
194 return None
195 return lpszDest.value
196
198 _PathCombineW = windll.shlwapi.PathCombineW
199 _PathCombineW.argtypes = [LPWSTR, LPWSTR, LPWSTR]
200 _PathCombineW.restype = LPWSTR
201
202 lpszDest = ctypes.create_unicode_buffer(u"", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1))
203 retval = _PathCombineW(lpszDest, lpszDir, lpszFile)
204 if retval == NULL:
205 return None
206 return lpszDest.value
207
208 PathCombine = GuessStringType(PathCombineA, PathCombineW)
209
210
211
212
213
215 _PathCanonicalizeA = windll.shlwapi.PathCanonicalizeA
216 _PathCanonicalizeA.argtypes = [LPSTR, LPSTR]
217 _PathCanonicalizeA.restype = bool
218 _PathCanonicalizeA.errcheck = RaiseIfZero
219
220 lpszDst = ctypes.create_string_buffer("", MAX_PATH)
221 _PathCanonicalizeA(lpszDst, lpszSrc)
222 return lpszDst.value
223
225 _PathCanonicalizeW = windll.shlwapi.PathCanonicalizeW
226 _PathCanonicalizeW.argtypes = [LPWSTR, LPWSTR]
227 _PathCanonicalizeW.restype = bool
228 _PathCanonicalizeW.errcheck = RaiseIfZero
229
230 lpszDst = ctypes.create_unicode_buffer(u"", MAX_PATH)
231 _PathCanonicalizeW(lpszDst, lpszSrc)
232 return lpszDst.value
233
234 PathCanonicalize = GuessStringType(PathCanonicalizeA, PathCanonicalizeW)
235
236
237
238
240 _PathFileExistsA = windll.shlwapi.PathFileExistsA
241 _PathFileExistsA.argtypes = [LPSTR]
242 _PathFileExistsA.restype = bool
243 return _PathFileExistsA(pszPath)
244
246 _PathFileExistsW = windll.shlwapi.PathFileExistsW
247 _PathFileExistsW.argtypes = [LPWSTR]
248 _PathFileExistsW.restype = bool
249 return _PathFileExistsW(pszPath)
250
251 PathFileExists = GuessStringType(PathFileExistsA, PathFileExistsW)
252
253
254
255
257 _PathFindExtensionA = windll.shlwapi.PathFindExtensionA
258 _PathFindExtensionA.argtypes = [LPSTR]
259 _PathFindExtensionA.restype = LPSTR
260 pszPath = ctypes.create_string_buffer(pszPath)
261 return _PathFindExtensionA(pszPath)
262
264 _PathFindExtensionW = windll.shlwapi.PathFindExtensionW
265 _PathFindExtensionW.argtypes = [LPWSTR]
266 _PathFindExtensionW.restype = LPWSTR
267 pszPath = ctypes.create_unicode_buffer(pszPath)
268 return _PathFindExtensionW(pszPath)
269
270 PathFindExtension = GuessStringType(PathFindExtensionA, PathFindExtensionW)
271
272
273
274
276 _PathFindFileNameA = windll.shlwapi.PathFindFileNameA
277 _PathFindFileNameA.argtypes = [LPSTR]
278 _PathFindFileNameA.restype = LPSTR
279 pszPath = ctypes.create_string_buffer(pszPath)
280 return _PathFindFileNameA(pszPath)
281
283 _PathFindFileNameW = windll.shlwapi.PathFindFileNameW
284 _PathFindFileNameW.argtypes = [LPWSTR]
285 _PathFindFileNameW.restype = LPWSTR
286 pszPath = ctypes.create_unicode_buffer(pszPath)
287 return _PathFindFileNameW(pszPath)
288
289 PathFindFileName = GuessStringType(PathFindFileNameA, PathFindFileNameW)
290
291
292
293
295 _PathFindNextComponentA = windll.shlwapi.PathFindNextComponentA
296 _PathFindNextComponentA.argtypes = [LPSTR]
297 _PathFindNextComponentA.restype = LPSTR
298 pszPath = ctypes.create_string_buffer(pszPath)
299 return _PathFindNextComponentA(pszPath)
300
302 _PathFindNextComponentW = windll.shlwapi.PathFindNextComponentW
303 _PathFindNextComponentW.argtypes = [LPWSTR]
304 _PathFindNextComponentW.restype = LPWSTR
305 pszPath = ctypes.create_unicode_buffer(pszPath)
306 return _PathFindNextComponentW(pszPath)
307
308 PathFindNextComponent = GuessStringType(PathFindNextComponentA, PathFindNextComponentW)
309
310
311
312
313
315 _PathFindOnPathA = windll.shlwapi.PathFindOnPathA
316 _PathFindOnPathA.argtypes = [LPSTR, LPSTR]
317 _PathFindOnPathA.restype = bool
318
319 pszFile = ctypes.create_string_buffer(pszFile, MAX_PATH)
320 if not ppszOtherDirs:
321 ppszOtherDirs = None
322 else:
323 szArray = ""
324 for pszOtherDirs in ppszOtherDirs:
325 if pszOtherDirs:
326 szArray = "%s%s\0" % (szArray, pszOtherDirs)
327 szArray = szArray + "\0"
328 pszOtherDirs = ctypes.create_string_buffer(szArray)
329 ppszOtherDirs = ctypes.pointer(pszOtherDirs)
330 if _PathFindOnPathA(pszFile, ppszOtherDirs):
331 return pszFile.value
332 return None
333
335 _PathFindOnPathW = windll.shlwapi.PathFindOnPathA
336 _PathFindOnPathW.argtypes = [LPWSTR, LPWSTR]
337 _PathFindOnPathW.restype = bool
338
339 pszFile = ctypes.create_unicode_buffer(pszFile, MAX_PATH)
340 if not ppszOtherDirs:
341 ppszOtherDirs = None
342 else:
343 szArray = u""
344 for pszOtherDirs in ppszOtherDirs:
345 if pszOtherDirs:
346 szArray = u"%s%s\0" % (szArray, pszOtherDirs)
347 szArray = szArray + u"\0"
348 pszOtherDirs = ctypes.create_unicode_buffer(szArray)
349 ppszOtherDirs = ctypes.pointer(pszOtherDirs)
350 if _PathFindOnPathW(pszFile, ppszOtherDirs):
351 return pszFile.value
352 return None
353
354 PathFindOnPath = GuessStringType(PathFindOnPathA, PathFindOnPathW)
355
356
357
358
360 _PathGetArgsA = windll.shlwapi.PathGetArgsA
361 _PathGetArgsA.argtypes = [LPSTR]
362 _PathGetArgsA.restype = LPSTR
363 pszPath = ctypes.create_string_buffer(pszPath)
364 return _PathGetArgsA(pszPath)
365
367 _PathGetArgsW = windll.shlwapi.PathGetArgsW
368 _PathGetArgsW.argtypes = [LPWSTR]
369 _PathGetArgsW.restype = LPWSTR
370 pszPath = ctypes.create_unicode_buffer(pszPath)
371 return _PathGetArgsW(pszPath)
372
373 PathGetArgs = GuessStringType(PathGetArgsA, PathGetArgsW)
374
375
376
377
378
379 -def PathIsContentTypeA(pszPath, pszContentType):
380 _PathIsContentTypeA = windll.shlwapi.PathIsContentTypeA
381 _PathIsContentTypeA.argtypes = [LPSTR, LPSTR]
382 _PathIsContentTypeA.restype = bool
383 return _PathIsContentTypeA(pszPath, pszContentType)
384
385 -def PathIsContentTypeW(pszPath, pszContentType):
386 _PathIsContentTypeW = windll.shlwapi.PathIsContentTypeW
387 _PathIsContentTypeW.argtypes = [LPWSTR, LPWSTR]
388 _PathIsContentTypeW.restype = bool
389 return _PathIsContentTypeW(pszPath, pszContentType)
390
391 PathIsContentType = GuessStringType(PathIsContentTypeA, PathIsContentTypeW)
392
393
394
395
397 _PathIsDirectoryA = windll.shlwapi.PathIsDirectoryA
398 _PathIsDirectoryA.argtypes = [LPSTR]
399 _PathIsDirectoryA.restype = bool
400 return _PathIsDirectoryA(pszPath)
401
403 _PathIsDirectoryW = windll.shlwapi.PathIsDirectoryW
404 _PathIsDirectoryW.argtypes = [LPWSTR]
405 _PathIsDirectoryW.restype = bool
406 return _PathIsDirectoryW(pszPath)
407
408 PathIsDirectory = GuessStringType(PathIsDirectoryA, PathIsDirectoryW)
409
410
411
412
414 _PathIsDirectoryEmptyA = windll.shlwapi.PathIsDirectoryEmptyA
415 _PathIsDirectoryEmptyA.argtypes = [LPSTR]
416 _PathIsDirectoryEmptyA.restype = bool
417 return _PathIsDirectoryEmptyA(pszPath)
418
420 _PathIsDirectoryEmptyW = windll.shlwapi.PathIsDirectoryEmptyW
421 _PathIsDirectoryEmptyW.argtypes = [LPWSTR]
422 _PathIsDirectoryEmptyW.restype = bool
423 return _PathIsDirectoryEmptyW(pszPath)
424
425 PathIsDirectoryEmpty = GuessStringType(PathIsDirectoryEmptyA, PathIsDirectoryEmptyW)
426
427
428
429
431 _PathIsNetworkPathA = windll.shlwapi.PathIsNetworkPathA
432 _PathIsNetworkPathA.argtypes = [LPSTR]
433 _PathIsNetworkPathA.restype = bool
434 return _PathIsNetworkPathA(pszPath)
435
437 _PathIsNetworkPathW = windll.shlwapi.PathIsNetworkPathW
438 _PathIsNetworkPathW.argtypes = [LPWSTR]
439 _PathIsNetworkPathW.restype = bool
440 return _PathIsNetworkPathW(pszPath)
441
442 PathIsNetworkPath = GuessStringType(PathIsNetworkPathA, PathIsNetworkPathW)
443
444
445
446
448 _PathIsRelativeA = windll.shlwapi.PathIsRelativeA
449 _PathIsRelativeA.argtypes = [LPSTR]
450 _PathIsRelativeA.restype = bool
451 return _PathIsRelativeA(pszPath)
452
454 _PathIsRelativeW = windll.shlwapi.PathIsRelativeW
455 _PathIsRelativeW.argtypes = [LPWSTR]
456 _PathIsRelativeW.restype = bool
457 return _PathIsRelativeW(pszPath)
458
459 PathIsRelative = GuessStringType(PathIsRelativeA, PathIsRelativeW)
460
461
462
463
465 _PathIsRootA = windll.shlwapi.PathIsRootA
466 _PathIsRootA.argtypes = [LPSTR]
467 _PathIsRootA.restype = bool
468 return _PathIsRootA(pszPath)
469
471 _PathIsRootW = windll.shlwapi.PathIsRootW
472 _PathIsRootW.argtypes = [LPWSTR]
473 _PathIsRootW.restype = bool
474 return _PathIsRootW(pszPath)
475
476 PathIsRoot = GuessStringType(PathIsRootA, PathIsRootW)
477
478
479
480
481
483 _PathIsSameRootA = windll.shlwapi.PathIsSameRootA
484 _PathIsSameRootA.argtypes = [LPSTR, LPSTR]
485 _PathIsSameRootA.restype = bool
486 return _PathIsSameRootA(pszPath1, pszPath2)
487
489 _PathIsSameRootW = windll.shlwapi.PathIsSameRootW
490 _PathIsSameRootW.argtypes = [LPWSTR, LPWSTR]
491 _PathIsSameRootW.restype = bool
492 return _PathIsSameRootW(pszPath1, pszPath2)
493
494 PathIsSameRoot = GuessStringType(PathIsSameRootA, PathIsSameRootW)
495
496
497
498
500 _PathIsUNCA = windll.shlwapi.PathIsUNCA
501 _PathIsUNCA.argtypes = [LPSTR]
502 _PathIsUNCA.restype = bool
503 return _PathIsUNCA(pszPath)
504
506 _PathIsUNCW = windll.shlwapi.PathIsUNCW
507 _PathIsUNCW.argtypes = [LPWSTR]
508 _PathIsUNCW.restype = bool
509 return _PathIsUNCW(pszPath)
510
511 PathIsUNC = GuessStringType(PathIsUNCA, PathIsUNCW)
512
513
514
515
516
517
518
519
521 _PathMakePrettyA = windll.shlwapi.PathMakePrettyA
522 _PathMakePrettyA.argtypes = [LPSTR]
523 _PathMakePrettyA.restype = bool
524 _PathMakePrettyA.errcheck = RaiseIfZero
525
526 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
527 _PathMakePrettyA(pszPath)
528 return pszPath.value
529
531 _PathMakePrettyW = windll.shlwapi.PathMakePrettyW
532 _PathMakePrettyW.argtypes = [LPWSTR]
533 _PathMakePrettyW.restype = bool
534 _PathMakePrettyW.errcheck = RaiseIfZero
535
536 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
537 _PathMakePrettyW(pszPath)
538 return pszPath.value
539
540 PathMakePretty = GuessStringType(PathMakePrettyA, PathMakePrettyW)
541
542
543
544
546 _PathRemoveArgsA = windll.shlwapi.PathRemoveArgsA
547 _PathRemoveArgsA.argtypes = [LPSTR]
548
549 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
550 _PathRemoveArgsA(pszPath)
551 return pszPath.value
552
554 _PathRemoveArgsW = windll.shlwapi.PathRemoveArgsW
555 _PathRemoveArgsW.argtypes = [LPWSTR]
556
557 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
558 _PathRemoveArgsW(pszPath)
559 return pszPath.value
560
561 PathRemoveArgs = GuessStringType(PathRemoveArgsA, PathRemoveArgsW)
562
563
564
565
567 _PathRemoveBackslashA = windll.shlwapi.PathRemoveBackslashA
568 _PathRemoveBackslashA.argtypes = [LPSTR]
569
570 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
571 _PathRemoveBackslashA(pszPath)
572 return pszPath.value
573
575 _PathRemoveBackslashW = windll.shlwapi.PathRemoveBackslashW
576 _PathRemoveBackslashW.argtypes = [LPWSTR]
577
578 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
579 _PathRemoveBackslashW(pszPath)
580 return pszPath.value
581
582 PathRemoveBackslash = GuessStringType(PathRemoveBackslashA, PathRemoveBackslashW)
583
584
585
586
588 _PathRemoveExtensionA = windll.shlwapi.PathRemoveExtensionA
589 _PathRemoveExtensionA.argtypes = [LPSTR]
590
591 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
592 _PathRemoveExtensionA(pszPath)
593 return pszPath.value
594
596 _PathRemoveExtensionW = windll.shlwapi.PathRemoveExtensionW
597 _PathRemoveExtensionW.argtypes = [LPWSTR]
598
599 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
600 _PathRemoveExtensionW(pszPath)
601 return pszPath.value
602
603 PathRemoveExtension = GuessStringType(PathRemoveExtensionA, PathRemoveExtensionW)
604
605
606
607
609 _PathRemoveFileSpecA = windll.shlwapi.PathRemoveFileSpecA
610 _PathRemoveFileSpecA.argtypes = [LPSTR]
611
612 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
613 _PathRemoveFileSpecA(pszPath)
614 return pszPath.value
615
617 _PathRemoveFileSpecW = windll.shlwapi.PathRemoveFileSpecW
618 _PathRemoveFileSpecW.argtypes = [LPWSTR]
619
620 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
621 _PathRemoveFileSpecW(pszPath)
622 return pszPath.value
623
624 PathRemoveFileSpec = GuessStringType(PathRemoveFileSpecA, PathRemoveFileSpecW)
625
626
627
628
629
631 _PathRenameExtensionA = windll.shlwapi.PathRenameExtensionA
632 _PathRenameExtensionA.argtypes = [LPSTR, LPSTR]
633 _PathRenameExtensionA.restype = bool
634
635 pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH)
636 if _PathRenameExtensionA(pszPath, pszExt):
637 return pszPath.value
638 return None
639
641 _PathRenameExtensionW = windll.shlwapi.PathRenameExtensionW
642 _PathRenameExtensionW.argtypes = [LPWSTR, LPWSTR]
643 _PathRenameExtensionW.restype = bool
644
645 pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH)
646 if _PathRenameExtensionW(pszPath, pszExt):
647 return pszPath.value
648 return None
649
650 PathRenameExtension = GuessStringType(PathRenameExtensionA, PathRenameExtensionW)
651
652
653
654
655
656
658 _PathUnExpandEnvStringsA = windll.shlwapi.PathUnExpandEnvStringsA
659 _PathUnExpandEnvStringsA.argtypes = [LPSTR, LPSTR]
660 _PathUnExpandEnvStringsA.restype = bool
661 _PathUnExpandEnvStringsA.errcheck = RaiseIfZero
662
663 cchBuf = MAX_PATH
664 pszBuf = ctypes.create_string_buffer("", cchBuf)
665 _PathUnExpandEnvStringsA(pszPath, pszBuf, cchBuf)
666 return pszBuf.value
667
669 _PathUnExpandEnvStringsW = windll.shlwapi.PathUnExpandEnvStringsW
670 _PathUnExpandEnvStringsW.argtypes = [LPWSTR, LPWSTR]
671 _PathUnExpandEnvStringsW.restype = bool
672 _PathUnExpandEnvStringsW.errcheck = RaiseIfZero
673
674 cchBuf = MAX_PATH
675 pszBuf = ctypes.create_unicode_buffer(u"", cchBuf)
676 _PathUnExpandEnvStringsW(pszPath, pszBuf, cchBuf)
677 return pszBuf.value
678
679 PathUnExpandEnvStrings = GuessStringType(PathUnExpandEnvStringsA, PathUnExpandEnvStringsW)
680