1- import random , win32com .client , subprocess , ctypes , os , strings
1+ import random , win32com .client , ctypes , os , strings , shutil
22import os , ctypes
33from utils import preferences
44
55
66def create_separator_shortcut (icon : str ):
77 delete_remnants ()
8-
98 random_number = random .randint (1000000000 , 9999999999 )
109
11- subprocess .call (f"md \" { preferences .working_folder } \\ shortcuts\\ " , shell = True )
10+ if not os .path .exists (preferences .working_folder + "\\ shortcuts" ):
11+ os .mkdir (preferences .working_folder + "\\ shortcuts" )
12+
1213 open (preferences .working_folder + f"\\ shortcuts\\ separator_shortcut_{ random_number } .vbs" , "w" , encoding = "utf8" ).write ("" )
1314
1415 shell = win32com .client .Dispatch ("WScript.Shell" )
@@ -30,7 +31,9 @@ def create_file_shortcut(file_path, name: str, icon_path: str, icon_index: int =
3031 file_name = path_list [len (path_list ) - 1 ]
3132 random_number_2 = str (random .randint (1000 , 9999 ))
3233
33- subprocess .call (f"md \" { preferences .working_folder } \\ shortcuts\\ " , shell = True )
34+ if not os .path .exists (preferences .working_folder + "\\ shortcuts" ):
35+ os .mkdir (preferences .working_folder + "\\ shortcuts" )
36+
3437 open (preferences .working_folder + f"\\ shortcuts\\ file_shortcut_{ random_number } .bat" , "w" , encoding = "utf8" ).write (f"chcp 65001 > nul\n cd \" { (file_path + random_number_2 ).replace (file_name + random_number_2 , '' )} \" \n \" { file_path } \" " )
3538 open (preferences .working_folder + f"\\ shortcuts\\ file_shortcut_{ random_number } .vbs" , "w" , encoding = "utf8" ).write (preferences .script_template_2 .replace ("(command)" , f"\" \" { preferences .working_folder } \\ shortcuts\\ file_shortcut_{ random_number } .bat\" \" " ))
3639
@@ -52,7 +55,9 @@ def create_folder_shortcut(folder_path: str, name: str, icon_path: str, icon_ind
5255 random_number = random .randint (1000000000 , 9999999999 )
5356 folder_path = folder_path .replace ('/' , '\\ ' )
5457
55- subprocess .call (f"md \" { preferences .working_folder } \\ shortcuts\\ " , shell = True )
58+ if not os .path .exists (preferences .working_folder + "\\ shortcuts" ):
59+ os .mkdir (preferences .working_folder + "\\ shortcuts" )
60+
5661 open (preferences .working_folder + f"\\ shortcuts\\ folder_shortcut_{ random_number } .bat" , "w" , encoding = "utf8" ).write (f"chcp 65001 > nul\n explorer \" { folder_path } \" " )
5762 open (preferences .working_folder + f"\\ shortcuts\\ folder_shortcut_{ random_number } .vbs" , "w" , encoding = "utf8" ).write (preferences .script_template_2 .replace ("(command)" , f"\" \" { preferences .working_folder } \\ shortcuts\\ folder_shortcut_{ random_number } .bat\" \" " ))
5863
@@ -69,12 +74,13 @@ def create_folder_shortcut(folder_path: str, name: str, icon_path: str, icon_ind
6974
7075
7176def delete_remnants ():
72- subprocess .call (f"rmdir /q /s \" { preferences .working_folder } \\ shortcut\" " , shell = True )
73- subprocess .call (f"mkdir \" { preferences .working_folder } \\ shortcut\" " , shell = True )
77+ if not os .path .exists (preferences .working_folder + "\\ shortcut" ):
78+ shutil .rmtree (preferences .working_folder + "\\ shortcut" )
79+ os .mkdir (preferences .working_folder + "\\ shortcut" )
7480
7581
7682def post_create_shortcut ():
77- subprocess . call ( f"explorer \" { preferences .working_folder } shortcut \" " , shell = True )
83+ os . startfile ( preferences .working_folder + "shortcut" )
7884
7985 ctypes .windll .user32 .MessageBoxW (
8086 None ,
@@ -85,7 +91,7 @@ def post_create_shortcut():
8591
8692
8793def get_folder_icon (folder_path : str ) -> str :
88- folder_config = subprocess . getoutput ( f"type \" { folder_path } \\ desktop.ini\" " ).split ("\n " )
94+ folder_config = open ( folder_path + " \\ desktop.ini" , "r" ). read ( ).split ("\n " )
8995 folder_icon = ("C:\\ Windows\\ System32\\ shell32.dll" , 4 )
9096
9197 for line in folder_config :
0 commit comments