import os
import win32netcon
import win32wnet
from win32wnet import WNetAddConnection2, NETRESOURCE
def get_parent_directory(path):
parent_directory = os.path.dirname(path)
return parent_directory
def create_subdirectory(full_path):
username = r'ZK\12356'
password = r'12345'
net_resource = NETRESOURCE()
network_path = get_parent_directory(full_path)
net_resource.lpRemoteName = network_path
net_resource.dwType = win32netcon.RESOURCETYPE_DISK
try:
WNetAddConnection2(
net_resource,
password,
username,
0
)
os.makedirs(full_path)
print(f"连接到网络共享 {network_path} 成功")
except Exception as e:
print(f"连接到网络共享失败: {e}")
return
#
# # 创建子目录
# try:
#
# print(f"子目录 {full_path} 创建成功")
# except OSError as e:
# print(f"子目录创建失败: {e}")
#
# # 断开网络共享连接
# try:
# win32wnet.WNetCancelConnection2(network_path, 0, True)
# print(f"断开网络共享连接 {network_path} 成功")
# except Exception as e:
# print(f"断开网络共享连接失败: {e}")
import subprocess
import time
import os
username = r'ZK\1231'
password = r'12345'
subprocess.Popen("net use E: \\\\ccnnsvs115fls01\\APP01\\POWERBI %s /USER:%s" % (password, username))
# time.sleep(1) # Short delay to allow E: drive to map before continuing
# newf = r'\\ccnnsvs115fls01\APP01\POWERBI\ss'
# os.mkdir(newf)
#
# filepath = os.path.join(newf, 'new_subdirectory.txt')
# with open(filepath, 'w') as f:
# f.write('aaa')
subprocess.Popen("net use E: /delete")