46 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| # Ask for the directory
 | |
| echo "Enter directory path:"
 | |
| read dir
 | |
| 
 | |
| while true; do
 | |
|     echo ""
 | |
|     echo "Menu:"
 | |
|     echo "1. Convert .txt files to .py in $dir"
 | |
|     echo "2. List ownership properties (ls -l) of all files in $dir"
 | |
|     echo "3. Count .sh files and subdirectories in $dir"
 | |
|     echo "4. Exit"
 | |
|     echo -n "Choose an option: "
 | |
|     read option
 | |
| 
 | |
|     case $option in
 | |
|         1)
 | |
|             for file in "$dir"/*.txt; do
 | |
|                 if [ -f "$file" ]; then
 | |
|                     new="${file%.txt}.py"
 | |
|                     mv "$file" "$new"
 | |
|                     echo "Renamed: $file -> $new"
 | |
|                 fi
 | |
|             done
 | |
|             ;;
 | |
|         2)
 | |
|             ls -l "$dir"
 | |
|             ;;
 | |
|         3)
 | |
|             sh_count=$(ls -1 "$dir"/*.sh 2>/dev/null | wc -l)
 | |
|             dir_count=$(ls -d "$dir"/*/ 2>/dev/null | wc -w)
 | |
|             echo ".sh file count: $sh_count"
 | |
|             echo "Subdirectory count: $dir_count"
 | |
|             ;;
 | |
|         4)
 | |
|             echo "Exiting..."
 | |
|             break
 | |
|             ;;
 | |
|         *)
 | |
|             echo "Invalid option. Please try again."
 | |
|             ;;
 | |
|     esac
 | |
| done
 | |
| 
 | |
| echo "Bye!"
 |