Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testSHFileOperation.py 2.0KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import os
  2. import win32api
  3. from win32com.shell import shell, shellcon
  4. def testSHFileOperation(file_cnt):
  5. temp_dir = os.environ["temp"]
  6. orig_fnames = [
  7. win32api.GetTempFileName(temp_dir, "sfo")[0] for x in range(file_cnt)
  8. ]
  9. new_fnames = [
  10. os.path.join(temp_dir, "copy of " + os.path.split(orig_fnames[x])[1])
  11. for x in range(file_cnt)
  12. ]
  13. pFrom = "\0".join(orig_fnames)
  14. pTo = "\0".join(new_fnames)
  15. shell.SHFileOperation(
  16. (
  17. 0,
  18. shellcon.FO_MOVE,
  19. pFrom,
  20. pTo,
  21. shellcon.FOF_MULTIDESTFILES | shellcon.FOF_NOCONFIRMATION,
  22. )
  23. )
  24. for fname in orig_fnames:
  25. assert not os.path.isfile(fname)
  26. for fname in new_fnames:
  27. assert os.path.isfile(fname)
  28. shell.SHFileOperation(
  29. (
  30. 0,
  31. shellcon.FO_DELETE,
  32. fname,
  33. None,
  34. shellcon.FOF_NOCONFIRMATION | shellcon.FOF_NOERRORUI,
  35. )
  36. )
  37. def testSHNAMEMAPPINGS(file_cnt):
  38. ## attemps to move a set of files to names that already exist, and generated filenames should be returned
  39. ## as a sequence of 2-tuples created from SHNAMEMAPPINGS handle
  40. temp_dir = os.environ["temp"]
  41. orig_fnames = [
  42. win32api.GetTempFileName(temp_dir, "sfo")[0] for x in range(file_cnt)
  43. ]
  44. new_fnames = [win32api.GetTempFileName(temp_dir, "sfo")[0] for x in range(file_cnt)]
  45. pFrom = "\0".join(orig_fnames)
  46. pTo = "\0".join(new_fnames)
  47. rc, banyaborted, NameMappings = shell.SHFileOperation(
  48. (
  49. 0,
  50. shellcon.FO_MOVE,
  51. pFrom,
  52. pTo,
  53. shellcon.FOF_MULTIDESTFILES
  54. | shellcon.FOF_NOCONFIRMATION
  55. | shellcon.FOF_RENAMEONCOLLISION
  56. | shellcon.FOF_WANTMAPPINGHANDLE,
  57. )
  58. )
  59. for old_fname, new_fname in NameMappings:
  60. print("Old:", old_fname, "New:", new_fname)
  61. assert len(NameMappings) == file_cnt
  62. testSHFileOperation(10)
  63. testSHFileOperation(1)
  64. testSHNAMEMAPPINGS(5)