PyBetterFileIO is the most intuitive, efficient, and accessible way to perform file input and output functions in python. Designed to improve the syntax of Python's included libraries, PyBetterFileIO is an effective tool. Create and edit files and folders, copy and move files and directories, and more. Treat your files and directories like objects in Python.
pip install PyBetterFileIOfromPyBetterFileIOimport*new_file=file("new_file.txt") # Instantiate a file object (required!)new_file.make() # Make the file in the defined directorynew_file.create() # Create the file in the defined directorynew_file.write("Hello World!") # Clears and writes to file's contentnew_file.append(" It's a beautiful day.") # Adds onto file's existing contentnew_file.replace("Hello World!", "Goodbye World!") # Finds and replaces file's contentnew_file.move_to("folder_or_path_to_move_to.optional") # Moves file to specified locationnew_file.rename("file.txt", "folder_to_move_to/file.txt") # Rename the filenew_file.delete() # Delete the filenew_file.remove() # Remove the filenew_file.copy("test_folder/fun_file.txt") # Copy file to parameter's locationnew_file.copy_and_rename("test_folder/fun_file.txt") # Copy file to parameter's locationnew_file.copy_to("test_folder/fun_file.txt") # Copy file to parameter's locationnew_file.read() # Returns file text contentnew_file.print() # Prints file text contentnew_file.exists() # Returns boolean if file existsnew_file.get_filename() # Returns file's pathnew_file.get_default_file_object() # Returns a default file object allowing new_file to act as: with open(...) as new_file:new_file.get_custom_file_object() # Returns a PyBetterFileIO file object from a default object where default is from: with open(...) as new_filenew_folder=folder("new_folder") # Instantiate a folder object (required!)new_folder.make() # Make the file in the defined directorynew_folder.create() # Create the file in the defined directorynew_folder.replace("not_needed_folder") # Replaces content of parameter's folder with object's contentnew_folder.rename("folder_to_move_to/old_file.txt") # Rename the filenew_folder.delete() # Delete the filenew_folder.remove() # Remove the filenew_folder.create_file("name_of_file.txt") # Create a file inside foldernew_folder.make_file("name_of_file.txt") # Make a file inside foldernew_folder.copy_to("test_folder") # Copy folder to parameter's locationnew_folder.copy_contents_to("test_folder") # Copy contents to parameter's locationnew_folder.move_to("test_folder") # Moves to parameter's location without keeping original directorynew_folder.list() # Returns a list of all files in folder objectnew_folder.read() # Returns file text contentnew_folder.print() # Prints file text contentnew_folder.exists() # Returns boolean if folder existsnew_folder.clear() # Clears folder contentnew_folder.get_foldername() # Returns file's pathFolder.clear_at("directory") # Clears specified directorywithopen("file.txt", 'w') asfile:
file.write()file("file.txt").make()withopen("file.txt", "w") asfile:
file.write("Hello World!")file("file.txt").write("Hello World!")# Assume already existing filewithopen('file.txt', 'r') asfile:
filedata=file.read()
filedata=filedata.replace('abcd', 'ram')
withopen('file.txt', 'w') asfile:
file.write(filedata)file("file.txt").replace("abcd", "ram")files=os.listdir("contents")
forfileinfiles:
shutil.copy(os.path.join("contents", file), os.path.join("other_content", "test_folder", file))folder("contents").copy_contents_to("other_content/test_folder")