Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #A list of file names
- clear
- #Read by line to handle filenames with spaces
- OGIFS = $IFS
- IFS=$(echo -en "\n\b")
- myfiles=$(ls)
- #A count of the files being processed, used to determine when new folder should be created
- filecount=1
- filelimit=25
- folderprefix="archivo_"
- foldersuffix=1
- filename=""
- foldername="$folderprefix$foldersuffix"
- $scriptlimit=10000
- if [ -d "$foldername" ]; then
- echo "Directory found."
- else
- echo "No directory found so a new one was created."
- mkdir "$foldername"
- fi
- for myfile in $myfiles
- do
- #exit to prevent script from running too long
- if [ $filecount -gt $scriptlimit ]; then
- exit 0
- fi
- filename="$myfile"
- #escape conditions
- if [[ "$myfile" = "\$"* ]]; then
- filename="\$myfile"
- fi
- if [[ "$myfile" = "\."* ]]; then
- filename="\$myfile"
- fi
- ((filecount++))
- if [ "$filecount" -gt "$filelimit" ]; then
- echo "----------$foldername"
- filecount=1
- ((foldersuffix++))
- foldername="$folderprefix$foldersuffix"
- if [ -d "$foldername" ]; then
- echo "Directory found."
- else
- echo "No directory found so a new one was created."
- mkdir "$foldername"
- fi
- fi
- echo "item $myfile moved to: $foldername"
- mv "$myfile" "$foldername/$myfile"
- done
- #Restore default
- IFS=$OGIFS
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement