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 Fri 31 Oct 2014, 06:54
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 Posts_count  
Author Message
tlchost

Joined: 05 Aug 2007
Posts: 1730
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_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: 1730
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_website 
Ibidem

Joined: 25 May 2010
Posts: 502
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: 1730
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_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: 1730
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_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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