Script Request

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
tlchost
Posts: 2057
Joined: Sun 05 Aug 2007, 23:26
Location: Baltimore, Maryland USA
Contact:

Script Request

#1 Post by tlchost »

This requirement is way over my head....hopefully someone can give me a hand.

I need a script where I can specify a particular path, i.e, nytimes/fiction and have the script delete all file extensions of a specified type

Something like

scriptname /nytimes/fiction mobi
or if I wanted to deleted the epup files
scriptname /nytimes/ epup

The variables are the directory path and the file extension

Thanks in advance for any help.

Thom

akash_rawal
Posts: 229
Joined: Wed 25 Aug 2010, 15:38
Location: ISM Dhanbad, Jharkhand, India

#2 Post by akash_rawal »

Code: Select all

#!/bin/sh

dirname="$1"
extension="$2"

find "$dirname" -name "*.$extension" -print |
while read file; do
    rm "$file"
done
Does this work?

tlchost
Posts: 2057
Joined: Sun 05 Aug 2007, 23:26
Location: Baltimore, Maryland USA
Contact:

#3 Post by tlchost »

Ah....my error

The directory structure is
nytimes/fiction/variable authorname/extension

it would need to look in all many authornames and perform the rm
akash_rawal wrote:

Code: Select all

#!/bin/sh

dirname="$1"
extension="$2"

find "$dirname" -name "*.$extension" -print |
while read file; do
    rm "$file"
done
Does this work?

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#4 Post by Ibidem »

tlchost wrote:Ah....my error

The directory structure is
nytimes/fiction/variable authorname/extension

it would need to look in all many authornames and perform the rm
akash_rawal wrote:

Code: Select all

#!/bin/sh

dirname="$1"
extension="$2"

find "$dirname" -name "*.$extension" -print |
while read file; do
    rm "$file"
done
Does this work?
That's what find is for. It will look in all subdirectories, recursively.

I presume that the files are (for example) *.mobi, not <author>/mobi (which a pedantic reading of your post would suggest)?

tlchost
Posts: 2057
Joined: Sun 05 Aug 2007, 23:26
Location: Baltimore, Maryland USA
Contact:

#5 Post by tlchost »

Ibidem wrote: I presume that the files are (for example) *.mobi, not <author>/mobi (which a pedantic reading of your post would suggest)?
Pedantic wins:

Examples:

/nytimes/fiction/authorname1/*.mobi
/nytimes/fiction/authorname2/*.mobi

So one might think of it as
/nytimes/fiction/authorname/*.extension
/nytimes/nonfiction/authorname/*.extension
where fiction/nonfiction are variables
authorname is a variable
extension is a variable

Thanks,

Thom

akash_rawal
Posts: 229
Joined: Wed 25 Aug 2010, 15:38
Location: ISM Dhanbad, Jharkhand, India

#6 Post by akash_rawal »

tlchost wrote:
Ibidem wrote: I presume that the files are (for example) *.mobi, not <author>/mobi (which a pedantic reading of your post would suggest)?
Pedantic wins:

Examples:

/nytimes/fiction/authorname1/*.mobi
/nytimes/fiction/authorname2/*.mobi

So one might think of it as
/nytimes/fiction/authorname/*.extension
/nytimes/nonfiction/authorname/*.extension
where fiction/nonfiction are variables
authorname is a variable
extension is a variable

Thanks,

Thom
Means you want to delete files at depth 2?

In your example you want to delete files named as "/nytimes/fiction/*/*.extension" and not "/nytimes/fiction/*.extension" or "/nytimes/fiction/*/*/*.extension"?

Then this might work:

Code: Select all

#!/bin/sh

dirname="$1"
extension="$2"

find "$dirname" -mindepth 2 -maxdepth 2 -name "*.$extension" -print |
while read file; do
    rm "$file"
done 

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#7 Post by jamesbond »

Check whether listing is correct:

Code: Select all

find /nytimes/fiction -path '*/authorname/*.mobi'
If correct,

Code: Select all

find /nytimes/fiction -path '*/authorname/*.mobi' -delete
will finish it.
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

tlchost
Posts: 2057
Joined: Sun 05 Aug 2007, 23:26
Location: Baltimore, Maryland USA
Contact:

Thanks

#8 Post by tlchost »

It seems that the directories created with the ebooks are all differnent in structure..so there may not be a universal script.

Thanks for all the responses.

I ended up with a kludgy solution..

looked at the directory nytimes, noted the subdirectories and based on that:

rm /mnt/home/nytimes/Books/Fiction/*/*.mobi
and
rm /mnt/home/nytimes/Books/Non-fiction/*/*.mobi

Since all the sub-directories can have different names...it's beyond me on how to do it, unless I did
rm /mnt/home/nytimes/*/*/*.mobi

Post Reply