Ignore Folder in Shell Script ?

Hi,

I currently use a script to extract *.deb files located in a Directory called
"/var/mobile/Media/Downloads"
The Problem is howver I want the script to ignore the folder:
"/var/mobile/Media/Downloads/New Debs and Files"
(it shall NOT decompile any of the files in that folder.

Here is the script I have so far (which decompiles said files in the "New Debs and Files" Folder aswell):

sudo chmod -R 777 /var/mobile/Media/Downloads
sudo chown -R mobile:mobile /var/mobile/Media/Downloads
find /var/mobile/Media/Downloads/ -name "*.deb" | xargs -I {} dpkg -x {} {}.x
find /var/mobile/Media/Downloads/ -name "*.deb" | xargs -I {} dpkg -e {} {}.x/DEBIAN
sudo chmod -R 777 /var/mobile/Media/Downloads
sudo chown -R mobile:mobile /var/mobile/Media/Downloads
#######
# Remove .deb.x extension from any directory name
# DIR=/var/mobile/Media/Downloads
DIR=/var/mobile/Media/Downloads
echo Before:
file $DIR/*
for old_sub in $DIR/*.deb.x; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/\.deb\.x$//")
    if [ -d "$new_sub" ]; then
      echo "$new_sub" already exists
      # take action, such as: rmdir "$new_sub"
      # take action, such as: rm -r "$new_sub"
      # take action, such as: exit
    fi
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*
ls -ld $DIR/*

If I understand what you're trying to do, try changing:

find /var/mobile/Media/Downloads/ -name "*.deb" | xargs -I {} dpkg -x {} {}.x
find /var/mobile/Media/Downloads/ -name "*.deb" | xargs -I {} dpkg -e {} {}.x/DEBIAN

to:

find /var/mobile/Media/Downloads/ -name '*.deb' -o \( -name 'New Debs and Files' -prune \) | xargs -I {} dpkg -x {} {}.x
find /var/mobile/Media/Downloads/ -name '*.deb' -o \( -name 'New Debs and Files' -prune \) | xargs -I {} dpkg -e {} {}.x/DEBIAN

Sadly it still extracts the debs in the Subfolder.

Maybe the solution would be to *only* extract the files inside the Downloads folder completly ignoring any subfolders there might be ?

If there is no solution to this I might aswell temporarily move the folder out of the way, but that is onyl my last resort.

Thanks.

EDIT:

Ha! that is too funny, even when I change my code to hamper with the permissions/and or move the folder away for the time the extracting takes place and move it back right after/rechange the permissions it STILL hampers with the debs in the sub dir:

sudo chmod -R 777 /var/mobile/Media/Downloads
sudo chown -R mobile:mobile /var/mobile/Media/Downloads

#sudo mv "/var/mobile/Media/Downloads/New Debs and Files" /var/mobile/Media/
sudo chmod -R 000 "/var/mobile/Media/Downloads/New Debs and Files"
sudo chown -R wheel:wheel "/var/mobile"Media/Downloads"New Debs and Files"

find /var/mobile/Media/Downloads/ -name "*.deb" | xargs -I {} dpkg -x {} {}.x
find /var/mobile/Media/Downloads/ -name "*.deb" | xargs -I {} dpkg -e {} {}.x/DEBIAN
sudo chmod -R 777 /var/mobile/Media/Downloads
sudo chown -R mobile:mobile /var/mobile/Media/Downloads
#######
# Remove .deb.x extension from any directory name
# DIR=/var/mobile/Media/Downloads
DIR=/var/mobile/Media/Downloads
echo Before:
file $DIR/*
for old_sub in $DIR/*.deb.x; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/\.deb\.x$//")
    if [ -d "$new_sub" ]; then
      echo "$new_sub" already exists
      # take action, such as: rmdir "$new_sub"
      # take action, such as: rm -r "$new_sub"
      # take action, such as: exit
    fi
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*
ls -ld $DIR/*
clear

#mv "/var/mobile/Media/New Debs and Files" "/var/mobile/Media/
sudo chmod -R 777 "/var/mobile/Media/Downloads/New Debs and Files"
sudo chown -R mobile:mobile "/var/mobile"Media/Downloads"New Debs