-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_junction.py
More file actions
37 lines (28 loc) · 972 Bytes
/
Copy pathtest_junction.py
File metadata and controls
37 lines (28 loc) · 972 Bytes
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
import os
import subprocess
import shutil
def test_junction():
target = "test_target_dir"
link = "test_junction_link"
# cleanup
if os.path.exists(target): shutil.rmtree(target)
if os.path.exists(link): os.remove(link) if os.path.islink(link) else os.rmdir(link)
os.makedirs(target)
# Create junction using mklink /J
cmd = f'mklink /J "{link}" "{target}"'
subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL)
if not os.path.exists(link):
print("Failed to create junction. Are you Admin?")
return
print(f"Testing path: {link}")
print(f"Exists: {os.path.exists(link)}")
print(f"IsLink: {os.path.islink(link)}")
if hasattr(os.path, 'isjunction'):
print(f"IsJunction: {os.path.isjunction(link)}")
else:
print("IsJunction: Not available in this python version")
# cleanup
os.rmdir(link)
os.rmdir(target)
if __name__ == "__main__":
test_junction()