Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 29 Nov 2014, 03:23
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Script Request
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
tlchost

Joined: 05 Aug 2007
Posts: 1741
Location: Baltimore, Maryland USA

PostPosted: Tue 02 Jul 2013, 10:07    Post subject:  Script Request  

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
Back to top
View user's profile Send private message Visit poster's website 
akash_rawal

Joined: 25 Aug 2010
Posts: 232
Location: ISM Dhanbad, Jharkhand, India

PostPosted: Tue 02 Jul 2013, 10:18    Post subject:  

Code:

#!/bin/sh

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

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


Does this work?
Back to top
View user's profile Send private message 
tlchost

Joined: 05 Aug 2007
Posts: 1741
Location: Baltimore, Maryland USA

PostPosted: Tue 02 Jul 2013, 10:50    Post subject:  

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:

#!/bin/sh

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

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


Does this work?
Back to top
View user's profile Send private message Visit poster's website 
Ibidem

Joined: 25 May 2010
Posts: 523
Location: State of Jefferson

PostPosted: Tue 02 Jul 2013, 13:08    Post subject:  

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:

#!/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)?
Back to top
View user's profile Send private message 
tlchost

Joined: 05 Aug 2007
Posts: 1741
Location: Baltimore, Maryland USA

PostPosted: Tue 02 Jul 2013, 19:27    Post subject:  

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
Back to top
View user's profile Send private message Visit poster's website 
akash_rawal

Joined: 25 Aug 2010
Posts: 232
Location: ISM Dhanbad, Jharkhand, India

PostPosted: Wed 03 Jul 2013, 11:34    Post subject:  

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:

#!/bin/sh

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

find "$dirname" -mindepth 2 -maxdepth 2 -name "*.$extension" -print |
while read file; do
    rm "$file"
done
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 2230
Location: The Blue Marble

PostPosted: Wed 03 Jul 2013, 11:35    Post subject:  

Check whether listing is correct:
Code:
find /nytimes/fiction -path '*/authorname/*.mobi'


If correct,
Code:
find /nytimes/fiction -path '*/authorname/*.mobi' -delete
will finish it.
_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
tlchost

Joined: 05 Aug 2007
Posts: 1741
Location: Baltimore, Maryland USA

PostPosted: Wed 03 Jul 2013, 21:39    Post subject: Thanks  

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
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0612s ][ Queries: 12 (0.0033s) ][ GZIP on ]