LINUX.ORG.RU

История изменений

Исправление Desmond_Hume, (текущая версия) :

Добавил временную метку, чтобы не было конфликта имён:

#!/bin/bash

now=$(date -d "today" +"%Y%m%d%H%M")
initial_folder="/home/$USER/Documents/Test Files/"
test_folder="/home/$USER/Documents/Test Files/test"
originalFiles_folder="/home/$USER/Documents/Test Files/original files/"

for a in "$initial_folder"*
	do
		function filetype_is {
							
			file "$a" |  cut -d ":" -f 2 | cut -d " " -f 2
		}		

		if [ $(filetype_is) = "directory" ]; then
			:
		elif [ $(filetype_is) = "Unicode" ]; then			
			mv "$a" "$a.$now" && mv "$a.$now" "$test_folder"
		elif [ $(filetype_is) = "ISO-8859" ]; then
			iconv -f WINDOWS-1251 -t UTF-8 -o "${a%}.$now.converted" "$a" && mv "${a%}.$now.converted" "$test_folder" 
		else 
			:
		fi
	done

find "$initial_folder" -maxdepth 1 -type f  -exec mv {} "$originalFiles_folder" \;

Исходная версия Desmond_Hume, :

Добавил временную метку, чтобы не было конфликта имён:

#!/bin/bash

now=$(date -d "today" +"%Y%m%d%H%M")
initial_folder="/home/$USER/Documents/Test Files/"
test_folder="/home/$USER/Documents/Test Files/test"
originalFiles_folder="/home/$USER/Documents/Test Files/original files/"
set -x
for a in "$initial_folder"*
	do
		function filetype_is {
							
			file "$a" |  cut -d ":" -f 2 | cut -d " " -f 2
		}		

		if [ $(filetype_is) = "directory" ]; then
			:
		elif [ $(filetype_is) = "Unicode" ]; then			
			mv "$a" "$a.$now" && mv "$a.$now" "$test_folder"
		elif [ $(filetype_is) = "ISO-8859" ]; then
			iconv -f WINDOWS-1251 -t UTF-8 -o "${a%}.$now.converted" "$a" && mv "${a%}.$now.converted" "$test_folder" 
		else 
			:
		fi
	done

find "$initial_folder" -maxdepth 1 -type f  -exec mv {} "$originalFiles_folder" \;