def split_efile(filename): fs = Filesplit() filedata = read_file(filename, "rb") split_length = len(filedata) // 2 if split_length % 2 != 0: split_length += 1 fs.split(file=filename, split_size=split_length, output_dir="cache") return True
def merge_decrypted(filename): fs = Filesplit() fs.merge(input_dir="cache", cleanup=True) dec_file = open("cache/" + filename, "rb") filedata = dec_file.read() dec_file_copy = open("decryptedFiles/" + filename, "wb") dec_file_copy.write(filedata) dec_file.close() dec_file_copy.close() return True
def get_model(): """ Loads model from the filesystem, merging it previously if needed. """ model_folder = os.path.join(os.environ['CovidTools'], 'mod_split_model') model_path = os.path.join(model_folder, 'model.pt') if not os.path.exists(model_path): fs = Filesplit() fs.merge(input_dir=os.path.join(model_folder, 'parts'), output_file=os.path.join(model_path), cleanup=False) return torch.load(model_path)
def _split_file_into_chunks(self, src_file_path: str, dst_dir_path: str) -> None: # define helper method that renames file chunks created with FileSplit def rename_chunk(chunk_path: str): directory, name, extension = self.split_file_path(chunk_path) chunk_id = re.match(r'^.*_(?P<id>\d+)$', name).group('id') new_chunk_path = os.path.join(directory, f'chunk_{chunk_id}{extension}') os.rename(chunk_path, new_chunk_path) return new_chunk_path # define callback function for FileSplit.split def note_created_file(file_path: str, file_path_list: list): self.log.debug(f'Creating file: {file_path}') file_path_list.append(file_path) # if source file size is bigger than defined chunk size split it into chunks if os.path.getsize(src_file_path) > self.chunk_byte_size: # initialize file paths list chunk_file_paths = list() # split file fs = Filesplit() fs.split(file=src_file_path, split_size=self.chunk_byte_size, output_dir=dst_dir_path, callback=lambda path, _: note_created_file( path, chunk_file_paths), newline=True) # rename files on file paths list chunk_file_paths = [ rename_chunk(path) for path in chunk_file_paths ] # delete manifest file manifest_file_path = os.path.join(dst_dir_path, 'fs_manifest.csv') if os.path.exists(manifest_file_path): os.remove(manifest_file_path) else: # copy and rename the source file _, _, extension = self.split_file_path(src_file_path) dst_file_path = os.path.join(dst_dir_path, f'chunk_1{extension}') shutil.copy(src_file_path, dst_file_path)
''' Python Assignment for splitting the file based on size - Submitted by - Shashi Prakash input format -> python main.py input.csv input.csv is majestic million csv file, which contains recods over a million for testing purpose''' import sys from fsplit.filesplit import Filesplit fs = Filesplit() #Callback function to print the split outputs in the terminal def split_cb(f, s): print("file: {0}, size: {1}".format(f, s)) #file -> input file name #split_size -> size of every splits in bytes #output_dir -> target directory to store the splits. fs.split(file=sys.argv[1], split_size=1000000, output_dir="/home/shashi/Assignmnet/Splits", callback=split_cb)
import sys from fsplit.filesplit import Filesplit fs = Filesplit() #Callback function to print the split outputs in the terminal def split_cb(f, s): print("file: {0}, size: {1}".format(f, s)) #file -> input file name #split_size -> size of every splits in bytes #output_dir -> target directory to store the splits. fs.split(file=sys.argv[1], split_size=1000000, output_dir="/home/anamika/Assignment/Splits", callback=split_cb)
async def chnnlzip(client, message): pablo = await edit_or_reply(message, "`Fetching All Files From This Channel!`") rndm = uuid.uuid4().hex un = get_text(message) dirz = f"./{rndm}/" media_count = 0 text_count = 0 os.makedirs(dirz) if un: chnnl = un else: chnnl = message.chat.id async for msg in client.search_messages(chnnl): if msg.sticker: rndmname = uuid.uuid4().hex if msg.sticker.mime_type == "application/x-tgsticker": file_name = os.path.join(dirz + rndmname + ".tgs") else: file_name = os.path.join(dirz + rndmname + ".wepb") try: await msg.download(file_name=file_name) except Exception as e: logging.info(e) elif msg.media: media_count += 1 try: await msg.download(file_name=dirz) except Exception as e: logging.info(e) elif msg.text: text_count += 1 f = open(os.path.join(dirz + f"{chnnl}.txt"), "a") f.write(f"[{msg.date}] - {msg.text} \n\n") total = text_count + media_count await pablo.edit( f"**Total Media :** `{total}` \n**Downloaded Media :** `{media_count}` \n**Total Texts Appended :** `{text_count}` \n**Now Zipping Files.**" ) shutil.make_archive(str(f"{chnnl}_ZippedByFridayUB"), "zip", dirz) await pablo.edit("`Zipped! Uploading Now!`") zip_name = f"{chnnl}_ZippedByFridayUB.zip" siz_e = os.stat(zip_name).st_size list_ = [] if siz_e > 2040108421: await pablo.edit( "`File Over 2GB, Telegram Doesn't Allow This. Trying To Split Files!`" ) fs = Filesplit() if not os.path.exists(f"./splitted_{chnnl}_{rndm}"): os.makedirs(f"./splitted_{chnnl}_{rndm}") fs.split( file=zip_name, split_size=2040108421, output_dir=f"./splitted_{chnnl}_{rndm}", ) file_list(f"./splitted_{chnnl}_{rndm}", list_) for oof in list_: if oof == "fs_manifest.csv": return await client.send_document( message.chat.id, oof, caption=f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`", ) shutil.rmtree(dirz) shutil.rmtree(f"./splitted_{chnnl}_{rndm}") if os.path.exists(zip_name): os.remove(zip_name) await pablo.delete() return await client.send_document( message.chat.id, zip_name, caption=f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`", ) os.remove(zip_name) shutil.rmtree(dirz) await pablo.delete()
async def chnnlzip(client, message): engine = message.Engine pablo = await edit_or_reply(message, engine.get_string("FILE_TOOLS_1")) rndm = uuid.uuid4().hex un = get_text(message) dirz = f"./{rndm}/" media_count = 0 text_count = 0 os.makedirs(dirz) if un: chnnl = un else: chnnl = message.chat.id async for msg in client.iter_history(chnnl): if msg.sticker: rndmname = uuid.uuid4().hex if msg.sticker.mime_type == "application/x-tgsticker": file_name = os.path.join(dirz + rndmname + ".tgs") else: file_name = os.path.join(dirz + rndmname + ".wepb") try: await msg.download(file_name=file_name) except Exception as e: logging.info(e) elif msg.media: media_count += 1 try: await msg.download(file_name=dirz) except Exception as e: logging.info(e) elif msg.text: text_count += 1 f = open(os.path.join(dirz + f"{chnnl}.txt"), "a") f.write(f"[{msg.date}] - {msg.text} \n\n") total = text_count + media_count await pablo.edit( engine.get_string("FILE_TOOLS_2").format(total, media_count, text_count)) shutil.make_archive(str(f"{chnnl}_ZippedByFridayUB"), "zip", dirz) await pablo.edit("`Zipped! Uploading Now!`") zip_name = f"{chnnl}_ZippedByFridayUB.zip" siz_e = os.stat(zip_name).st_size list_ = [] if siz_e > 2040108421: await pablo.edit(engine.get_string("FILE_TOOLS_3")) fs = Filesplit() if not os.path.exists(f"./splitted_{chnnl}_{rndm}"): os.makedirs(f"./splitted_{chnnl}_{rndm}") fs.split( file=zip_name, split_size=2040108421, output_dir=f"./splitted_{chnnl}_{rndm}", ) file_list(f"./splitted_{chnnl}_{rndm}", list_) for oof in list_: if oof == "fs_manifest.csv": return await client.send_document( message.chat.id, oof, caption= f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`", ) shutil.rmtree(dirz) shutil.rmtree(f"./splitted_{chnnl}_{rndm}") if os.path.exists(zip_name): os.remove(zip_name) await pablo.delete() return await client.send_document( message.chat.id, zip_name, caption= f"**Total :** `{total}` \n**Total Media :** `{media_count}` \n**Total Text :** `{text_count}`", ) os.remove(zip_name) shutil.rmtree(dirz) await pablo.delete()
from mega import Mega # importing import glob, os from fsplit.filesplit import Filesplit fs = Filesplit() inp1=int(input("Enter the split size in KB: ")) fs.split(file="./output/data.file", split_size=inp1*1000, output_dir="./output/divided") os.remove("./output/data.file") print("Files are divided, Please check output/divided folder") mega = Mega() # creating instance of mega print("\nPlease wait, logging in .....") m = mega.login("email", "password") #email id and passwor of www.mega.nz print("login done !! ") filename=[] os.chdir("./output/divided") for file in glob.glob("*.file"): filename.append(file) print("No. of division created:",len(filename)) print("Uploading file in progress ....") for i in range(len(filename)): file_upload=filename[i] file = m.upload(file_upload)
ap.add_argument("-o", "--file", required=True, help="Output file name") ap.add_argument("-l", "--log", required=False, help="When set to True, execution log is written to log_split.txt") ap.add_argument("-c", "--clean", required=False, help="Removes split files after merging them") args = vars(ap.parse_args()) def merge_cb(f, s): print("file: {0}, size: {1}".format(f, s)) if(bool(args['log'])): fo = open(args['input_dir']+"\log_merge.txt","a") fo.write("file: {0}, size: {1}\n".format(f, s)) fo.close() try: args['input_dir'] = args['input_dir'].replace("\\","/") args['file'] = args['input_dir'] + "/" + args['file'] if(os.path.isdir(args['input_dir'])): if(len(os.listdir(args['input_dir']))==0): raise ValueError("Input directory should not be empty! Exiting...") else: raise ValueError("Input directory path is invalid") fs = Filesplit() fs.merge(input_dir=args['input_dir'], output_file=args['file'], callback=merge_cb, cleanup=bool(args['clean'])) print("Merging sucessfully completed!") except ValueError as ve: print(ve) except Exception as e: print("Oops!", e.__class__, "occurred.")
args['output_dir'] = args['output_dir'].replace("\\", "/") args['file'] = args['file'].replace("\\", "/") try: if (os.path.isdir(args['output_dir'])): if (bool(args['force'])): delete_files() if (len(os.listdir(args['output_dir'])) != 0): raise ValueError("Output directory should be empty! Exiting...") else: os.mkdir(args['output_dir']) if not os.path.isfile(args['file']): raise ValueError("Input file path is invalid") fs = Filesplit() fs.split(file=args['file'], split_size=int(args['split_size']), output_dir=args['output_dir'], callback=split_cb, new_line=bool(args['newline']), include_header=bool(args['header'])) print("Splitting sucessfully completed!") except ValueError as ve: print(ve) except Exception as e: print("Oops!", e.__class__, "occurred.")
tk.Tk().withdraw() p = filedialog.askopenfilename( title='Choose the file location') message = open(p, "rb").read() print(p) encryption.encrypting_file(message, key, p) p = "../" os.chdir(p) print(os.getcwd()) os.system("python megaauth.py") break else: break elif main_input == 2: fs = Filesplit() folder_selected = filedialog.askdirectory( title='Choose the directory file location') fs.merge(input_dir=folder_selected) os.chdir(folder_selected) os.remove("./fs_manifest.csv") filename = [] #os.chdir("./output/divided") for file in glob.glob("*.file"): filename.append(file) for i in range(len(filename) - 1): os.remove(filename[i + 1]) decrypt.decryption()
fluid.install_check.run_check() # --------------------- 请你不要改 start----------------------------- # 项目的base目录 BASE_DIR = str(Path(os.path.abspath(__file__)).parent) # 模型文件目录 # 文本检测模型 DET_MODEL_PATH = os.path.join(BASE_DIR, 'backend', 'models', 'ch_det') # 文本识别模型 REC_MODEL_PATH = os.path.join(BASE_DIR, 'backend', 'models', 'ch_rec') # 查看该路径下是否有文本模型识别完整文件,没有的话合并小文件生成完整文件 if 'inference.pdiparams' not in (os.listdir(REC_MODEL_PATH)): fs = Filesplit() fs.merge(input_dir=REC_MODEL_PATH) # 字典路径 DICT_PATH = os.path.join(BASE_DIR, 'backend', 'ppocr', 'utils', 'ppocr_keys_v1.txt') # 默认字幕出现的大致区域 class SubtitleArea(Enum): # 字幕区域出现在下半部分 LOWER_PART = 0 # 字幕区域出现在上半部分 UPPER_PART = 1 # 不知道字幕区域可能出现的位置 UNKNOWN = 2
from fsplit.filesplit import Filesplit fs = Filesplit() fs.split(file='SampleMP3.mp3', split_size=50000, output_dir='.')
# Author: Mandeep Singh # Location: Moon # Date: 23/09/2023 import os #import flask from fsplit.filesplit import Filesplit fs = Filesplit() print(os.listdir()) #Print the contents of the directory using os module. #os.listdir()) is a external module Print the contents of the directory using os module.
! pip install filesplit from fsplit.filesplit import Filesplit fs = Filesplit() filedir=input("Enter the complete file path") outdir=input("Enter the complete path of the directory where you want to store the output files") choice=int(input("Do you want to split the file in \n 1.KB's \n 2.MB's \n 3.GB's \n")) if(choice == 1): x=int(input("Enter the split size for KB split")) x=x*1024 elif(choice == 2): x=int(input("Enter the split size for MB split")) x=x*1024*1024 elif(choice == 3): x=int(input("Enter the split size for GB split")) x=x*1024*1024*1024 else: print("Wrong Input") f_size=x print(f_size) def split_cb(f, s): print("file: {0}, size: {1}".format(f, s)) fs.split(file=filedir, split_size=f_size, output_dir=outdir, callback=split_cb)
# dictionary dumped as json in a json file with open('students.csv', 'w') as fp: json.dump(student_data, fp) def main(): number_of_students = 10000 input_data(number_of_students) main() from fsplit.filesplit import Filesplit fs = Filesplit() def split_cb(f, s): print("file: {0}, size: {1}".format(f, s)) fs.split(file="students.xml", split_size=2000000, output_dir="Downloads/CSVfile", callback=split_cb) from fsplit.filesplit import Filesplit fs = Filesplit()