Anhang:
File Split
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202 | #!/bin/bash
#
# Nautilus file split script v1.10
# Written by comicinker, January 2008 - comicinker@gmx.de
#
# This split script must be called from Nautilus!
# Place this script in your nautilus-scripts directory and make sure
# it's executable (chmod 775 this_script.sh) and it will show up in
# the, "Scripts" menu when files are right-clicked from within your
# Nautilus file manager. Please report any bugs to comicinker@gmx.de.
#
# Featues:
# Splits one file
# Resulting file name: "file name.dum_000"
# Prepared file sizes as well as manual input
# Don't touch the origin file
# Warning if more than 30 files (optional) will be created
#
# Don'ts
# Won't check for disk space
# Won't split in more than 1000 files
# Won't create md5 befor splitting (mabe v2)
#
# You can merge your files in a terminal with cat filename_* > new_file
# Or use the merge script File_Merge for Nautilus from me
#
# This program is free software. It is distributed in the hope
# that it will be useful, but WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
######################################################################
##################
# USER OPTIONS #
##################
# Gives a warnig if more than ... files are created
# set to 1000 if no wanted
FILE_NUMBER_WARING="30"
#####################################################
# YOU SHOULDN'T MODIFY ANYTHING BELOW THIS POINT! #
#####################################################
# Set some script variables
FILE_NUMBER_MAXIMUM="1000"
the_file=$1
if [ "$NAUTILUS_SCRIPT_CURRENT_URI" == "x-nautilus-desktop:///" ]; then
files_path=$HOME"/Desktop"
else
files_path=`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed -e 's/^file:\/\///; s/%20/\ /g'`
fi
gui=`which zenity`
split_file=`which split`
error_input= "no"
error_file_number="no"
# Split function
func_split()
{ # Watch out! () would create a subshell with own variables.
dialog_title="Select file size"
dialog_type="--list"
dialog_subtype="--radiolist"
dialog_height="350"
dialog_width="250"
dialog_text="Please select the desired file size"
dialog_column1=""
dialog_column2="Size"
dialog_column3="Info"
RESULT=`zenity "$dialog_type" "$dialog_subtype" --title "$dialog_title" --text="$dialog_text" --width="$dialog_width" --height="$dialog_height" \
--column "$dialog_column1" --column "$dialog_column2" --column "$dialog_column3" --hide-column=2 \
\"\" Manual "Input own file size" \
\"\" 1474k "1.44 MB Floppy" \
\"\" 5m "E-Mail (5 MB)" \
\"\" 15m "Share (15 MB)" \
\"\" 100m "100 MB" \
\"\" 650m "650 MB CD" \
\"\" 700m "700 MB CD" \
\"\" 1024m "1 GB, Best for DVD" \
\"\" 4300m "DVD single layer" \
` #<- important sign `
#if $RESULT has zero-length
if [ -z "$RESULT" ];then
return
fi
if [ "$RESULT" = "Manual" ];then
split_size=`zenity --entry --text "Enter file size manually. Example: 10 MegaByte: 10m" --title "Enter size"`
if [ -z "$split_size" ]; then
return # cancel if nothing or cancel entered
fi
else
split_size="$RESULT"
fi
# The orign file size in bytes
file_size=`stat -c%s "$the_file"`
# the divider for byte, kilo or mega is hidden in the end of split_size. just delete all numbers, the last left digit is a hint for our divider
divider=`echo "$split_size" | tr -d '[0-9]'`
# if nothing left
if [ -z "$divider" ];then
divider="1"
elif [ "$divider" = "b" ];then
divider="1"
elif [ "$divider" = "k" ];then
divider="1024"
elif [ "$divider" = "m" ];then
divider="1048576"
else
error_input="yes"
return #return for functions, exit for subshells
#wrong value entered!
fi
#calculate the resulting number of files
temp1=`expr "$file_size" / "$divider"`
temp2=`echo "$split_size" | tr -d '[a-z]'`
file_count=`expr "$temp1" / "$temp2"`
# check resulting file count
if [ "$file_count" -gt "$FILE_NUMBER_WARING" ];then # see man test for more info about -gt
zenity --question --title "Split files resulting files" --text "The number of resulting files exceeds $FILE_NUMBER_WARING files. Proceed?"
if [ $? = 1 ];then # check the last return value ("No" was answered)
# error_file_number="yes" # This would display a error message. unnessesary
return
fi
fi
# we only allow 1000 files!
if [ "$file_count" -gt "$FILE_NUMBER_MAXIMUM" ];then
error_file_number="yes"
return
fi
# Check file existens
file_name=`basename "$the_file"| sed -e "s/ /\ /g"` # get the filename only and replace " " with "\ "
found=`find . -name "${file_name}_*"` # find files in current directory only
if [[ -n "${found}" ]]; then #found something similar (found non-zero)
zenity --question --title "Confirm overwrite" --text "Files with `echo $file_name`_000 scheme already exists. Overwrite?"
if [[ $? = "1" ]]; then # cancel clicked
return
fi
fi
# 3 digits(->1000Files maximum) for file ending, verbose should do progress status
(split --bytes="$split_size" --suffix-length=3 --numeric-suffixes --verbose "${the_file}" "${the_file}"_ 2>&1 \
) | zenity --progress --pulsate --text "Splitting" --auto-kill
# split stops after current part is finished
}
# Errors function
func_errors()
{
display_error="no"
if [ -x "$gui" ]; then
result=""
else
result="Zenity NOT found. This utility is required!; "
display_error="yes"
fi
if [ -x "$split_file" ]; then
result=`echo "$result"`
else
result=`echo "$result split NOT found. This utility is required!; "`
display_error="yes"
fi
if [ "$error_input" = "yes" ]; then
display_error="yes"
result=`echo "$result Input error. Read man split which values are allowed; "`
fi
if [ "$error_file_number" = "yes" ]; then
display_error="yes"
result=`echo "$result Too many Files (1000 Maximum); "`
fi
echo $result
dialog_title="Split File Error!"
dialog_type="--error"
if [ "$display_error" = "yes" ];then
zenity --title "$dialog_title" "$dialog_type" --text "$result"
fi
exit 1
}
# Check for required Tools. actually, this is the beginning point of the script
if [[ -x "$gui" && -x "$split_file" ]]; then
func_split
fi
func_errors
exit 0
|
Anhang herunterladen
Diese Revision wurde am 29. Januar 2008 01:17 von comicinker erstellt.