First
This commit is contained in:
		
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | # Spaceify | ||||||
|  |  | ||||||
|  | This is a quickly put together utility. It takes a folder, and tries to open eveyr text file in it. | ||||||
|  |  | ||||||
|  | It then turns every tab (\t) into 4 spaces, beacause IT'S THE LAW. | ||||||
|  |  | ||||||
|  | ``` | ||||||
|  | usage: spaceify.py [-h] -f FOLDER | ||||||
|  |  | ||||||
|  | options: | ||||||
|  |   -h, --help            show this help message and exit | ||||||
|  |   -f FOLDER, --folder FOLDER | ||||||
|  |                         Folder to search in | ||||||
|  | ``` | ||||||
							
								
								
									
										46
									
								
								spaceify.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										46
									
								
								spaceify.py
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,46 @@ | |||||||
|  | #!/usr/bin/env python3 | ||||||
|  | #coding: utf-8 | ||||||
|  | import os | ||||||
|  | import sys | ||||||
|  |  | ||||||
|  | def get_args(): | ||||||
|  |     '''Gets all the arguments passed to the script and returns them in a parse_args()-type object. | ||||||
|  |     No args | ||||||
|  |     Returns: | ||||||
|  |     -args : an args object containing all the optional arguments passed to the script. | ||||||
|  |     ''' | ||||||
|  |     import argparse | ||||||
|  |  | ||||||
|  |     parser = argparse.ArgumentParser() | ||||||
|  |     parser.add_argument("-f", "--folder", help = "Folder to search in", action="store", type=str, required=True) | ||||||
|  |  | ||||||
|  |     #Creating the args object | ||||||
|  |     args=parser.parse_args() | ||||||
|  |  | ||||||
|  |     return args | ||||||
|  |  | ||||||
|  | def spaceify(filepath): | ||||||
|  |     """Spaceify the file given by the absolute path filepath. | ||||||
|  |     """ | ||||||
|  |  | ||||||
|  |     with open(filepath, "r") as myfile: | ||||||
|  |         myfile = myfile.read() | ||||||
|  |  | ||||||
|  |     myfile.replace("\t", "    ") | ||||||
|  |     with open(filepath, "w") as yourfile: | ||||||
|  |         yourfile.write(myfile) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | args = get_args() | ||||||
|  | look_folder = args.folder | ||||||
|  | if look_folder[-1] == "/": | ||||||
|  |     look_folder = look_folder[:-1] | ||||||
|  |  | ||||||
|  | for thing in os.listdir(look_folder): | ||||||
|  |     fpath = f"{look_folder}/{thing}" | ||||||
|  |     if os.path.isfile(fpath): | ||||||
|  |         try: | ||||||
|  |             print(f"Working on {fpath}") | ||||||
|  |             spaceify(fpath) | ||||||
|  |         except Exception as e: | ||||||
|  |             print(f"Got exception {e} for {fpath}, sorry") | ||||||
							
								
								
									
										2
									
								
								testdir/1.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								testdir/1.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  |     iofjqofjiq | ||||||
|  |     sfsef fsfesfe | ||||||
		Reference in New Issue
	
	Block a user