CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Delete all files from a dir .

 



yotam_k
Deleted

Mar 3, 2001, 7:14 AM

Post #1 of 24 (6900 views)
     Delete all files from a dir .  

Could someone tell me the code of deleting all files from a definded dir .

lets call the dir "DATA" .
If You need this all the files has the prefix ".data" .

Thanks !




SirAnvil
Deleted

Mar 3, 2001, 8:55 AM

Post #2 of 24 (6899 views)
     Re: Delete all files from a dir . [In reply to]  

I've never done this but if your running on a unix/linux server couldn't you just use the unlink command on the DATA directory like you would for a file?

SirAnvil
www.christiangamers.org


muinatit
Deleted

Mar 3, 2001, 9:32 AM

Post #3 of 24 (6897 views)
     Re: Delete all files from a dir . [In reply to]  


Code
unlink (/path/to/data/*);

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


yotam_k
Deleted

Mar 3, 2001, 2:14 PM

Post #4 of 24 (6894 views)
     Re: Delete all files from a dir . [In reply to]  

Sorry , But It's Not Working....




Jasmine
Administrator / Moderator

Mar 3, 2001, 3:35 PM

Post #5 of 24 (6892 views)
     Re: Delete all files from a dir . [In reply to]  


Code
system ( "rm", "-rf", "/path/of/directory/to/delete" );

Remember, there's no turning back from this one.



yotam_k
Deleted

Mar 4, 2001, 8:31 AM

Post #6 of 24 (6890 views)
     Re: Delete all files from a dir . [In reply to]  

It's not exectly what I'v asked , I wanted a function that deletes all the files in the directory and this one deletes the directory , but I handled It myself although I'll be Glad To get The function that does what I'v Asked For .

I think the function should read the DIR and then wuth a foreach loop delete every file .

All I need from you in this case is the way to read a directory .




Jean
User


Mar 4, 2001, 9:16 AM

Post #7 of 24 (6889 views)
     Re: Delete all files from a dir . [In reply to]  

That's possibly what you wanted.
Of course, what you actually needed is the loop itself
and not the insides, but if you want to, you can use that
in a recursive function that calls itself in case dir is found,
otherwise just removes the file.


Code
my $dir = "/path/name"; 
my $file;

opendir (DIR, "$dir") or die "Unable to open $dir";
while ( $file = readdir(DIR) )
{
print("FILE $file \n") if (-f $file);
print("<DIR> $file \n") if (-d $file);
}
closedir (DIR);

P.S. No offence meant, but IMHO it's not kind of question that is supposed to be posted in the Advanced ...


Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com


parham_m_s
journeyman

Mar 4, 2001, 9:47 AM

Post #8 of 24 (6888 views)
     Re: Delete all files from a dir . [In reply to]  

sorry for not adding errors and all the extra stuff in this.. but here's my solution:

Code
opendir (DIR,"path to dir"); 
@files = readdir(DIR);
closedir (DIR);
foreach $files (@files) {
unlink("path to dir/$files");
}
rmdir("path to dir");



japhy
Enthusiast / Moderator

Mar 4, 2001, 10:51 AM

Post #9 of 24 (6886 views)
     Re: Delete all files from a dir . [In reply to]  

I don't know how many times I've had to say this, but unlink() does not take a file glob!. If you want a file glob, use the glob() function!


Code
unlink glob "/path/to/files/*";

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


yotam_k
Deleted

Mar 5, 2001, 7:23 AM

Post #10 of 24 (6875 views)
     Re: Delete all files from a dir . [In reply to]  

Thanks MAn .
This : unlink glob "/delete/path/*";
Has don The Job !

Thanks !



zanardi
journeyman

Mar 5, 2001, 4:29 PM

Post #11 of 24 (6866 views)
     Re: Delete all files from a dir . [In reply to]  

kinda off topic, but yotam_k I've noticed alot of your threads in here dont really seem to be 'Advanced' problems, you should maybe post in intermediate forum :P

----------------------
Fueled By ZCom


yotam_k
Deleted

Mar 6, 2001, 3:59 AM

Post #12 of 24 (6859 views)
     Re: Delete all files from a dir . [In reply to]  

The Thing is that My problems are a memory colapse...

And by the way , I dont think It's your job to elect me on this .
It's The Admin's Job , Don't try to make yourself as One .



Jasmine
Administrator / Moderator

Mar 6, 2001, 9:27 AM

Post #13 of 24 (6855 views)
     Re: Delete all files from a dir . [In reply to]  

yotam_k

I agree with zanardi. Would you please post in the intermediate forums?

Jasmine



yotam_k
Deleted

Mar 9, 2001, 12:37 AM

Post #14 of 24 (6843 views)
     Re: Delete all files from a dir . [In reply to]  

can't you just help?

Forget all the adavanced and begginer
just help without any calculations if it's relevant or not .

Jasmine , I think you will have alot of authority problems
mybe you don't have any authority I dont know .

Stop Being Such A goffy and geek

Please ???????????




(This post was edited by japhy on Mar 9, 2001, 5:38 AM)


japhy
Enthusiast / Moderator

Mar 9, 2001, 6:47 AM

Post #15 of 24 (6842 views)
     Re: Delete all files from a dir . [In reply to]  

You seem to be forgetting something, yotam_k. We helped you. Do you know how much money I got for helping you?

Does Jasmine get paid to answer questions on this forum? No.

Do I get paid to do it? No.

Would you rather not have your questions answered here? Would you rather see the knowledge of the people on this forum go elsewhere?

I help out on this forum for two reasons: 1) Jasmine asked me to, and 2) there are a lot of people out there having trouble with Perl because of how they learned it. My professional goal is to be a Perl instructor; I want to reduce the number of people that write crappy Perl code, frankly. That's what I'm after.

And we said "please". "Please post in the intermediate forum." And you responded such that I had to edit your post.

Don't think just because you're you, you can make up your own rules here. "NO PARKING BETWEEN 11 PM and 6 AM" applies to you just as much as it applies to me. If we ask that certain types of questions -- or certain levels of programmers -- reside in a particular forum, there's a reason.

And I stand by this decision. Deleting files in a directory is not a mythical or difficult task. It's been done by many people before, and it's not something that requires a mastery of Perl. Using HTML::Template, or arrays of hash references, are more difficult topics, and warrant being asked about in this particular section.

And Jasmine is the authority around here. These forums are hers. Her idea. Her ambition. Her project. Have you ever said "thank you" to her?

She happens to be the admin, and the admin has asked you to post your questions in a different section.

Perhaps you have the authority problem.



Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


parham_m_s
journeyman

Mar 10, 2001, 11:24 AM

Post #16 of 24 (6835 views)
     Re: Delete all files from a dir . [In reply to]  

yotam_k, maybe next time you'll be a little bit more appreciative of the help everyone's given you. You should really research who's you're telling off before actually doing it.



yotam_k
Deleted

Mar 10, 2001, 2:30 PM

Post #17 of 24 (6830 views)
     Re: Delete all files from a dir . [In reply to]  

I have Two Things For You japhy .

1. You Edited My Messege And done two things to her :
a. Lost The Catch
b. Lost The Subject at all .

2. I haven't demanded anything , Just all what I want that people won't answer me answers like Post It in another forum . You Don't Wanna help?
Ok , I won't claim anything against you , If I'll Post Here and It's not suiteable So What?
Don't Answer and thats all the deal .

When It's In Intermediate You Don't Answer?
You Do .

Tell Me just what will make a differnce where I Post It?

Oh and by the way , Tell Me Japhy , If It's Such A Simple Question why 5 Differn't People tryied To Help And Had no success???

And One last thing , I have NEVER , NEVER !!! Said that Jasmine Had No authority . PLEASE notice How you Edit Someone Ideas and thoughts .
I think All you Should Have Done Is removing the forrbidden word I have Used and I do admit It was in purpose , It's How I speak and It was An unseperated part of my messege .

And One More Thing , parham_m_s , I Said thanks After The good answer of Japhey .



And last thing , I refuse to say
Thanks To The Slapper.

There Is An Old saying "When you get one slap on your cheack , You Never , NEVER , Give the other one "

And I'v never talked To you from height , Do not Do this to Me .

BYE.




Jasmine
Administrator / Moderator

Mar 10, 2001, 3:28 PM

Post #18 of 24 (6828 views)
     Re: Delete all files from a dir . [In reply to]  

yotam_k,

You have posted questions and received answers. You said to japhy "Has don The Job !", so you admitted that you have been helped here. Why then, choose to contradict yourself in the same post?

Perhaps the problem is not with the replies you get, but with the questions you give. Asking a question is one thing "gimme code that does this" is something else entirely.

Regardless, it seems clear that PerlGuru may not be the place for you to post your questions. Please feel free to visit the other newsgroups or forums that may be available to you. Or, learn like we did, by self-study. Learning Perl, Programming Perl, etc. are excellent places to start. The Perl Cookbook is a great place to find useful code snippets.

If you choose to continue posting here, we ask that you post to the correct forum, remember that replies are voluntary, and show consideration both for us and our other users. Posting in the incorrect forum will get your post deleted. Rudeness will do the same.

Jasmine
Administrator



japhy
Enthusiast / Moderator

Mar 10, 2001, 9:20 PM

Post #19 of 24 (6826 views)
     Re: Delete all files from a dir . [In reply to]  

The only text I edited out of your message was the line "F-U-C-K, with you all". I promise. I have no reason to be lying to you about that. I found that line un-needed, and removed it. The rest stayed as it was.

Honestly, when I see a simple question in the Advanced forum, I often don't answer. Why? Because I realize the person is just trying to get attention and make their question seem "urgent", and doesn't care about paying attention to things. In my mind, such a person is probably not a Perl programmer, but someone who accidentally led their boss to believe they knew Perl, and now has to fix a program up.

You said the following (which I did not edit in any way, shape, or form):

"Jasmine , I think you will have alot of authority problems
mybe you don't have any authority I dont know."

Unless you mis-spoke, you are saying "maybe Jasmine does not have authority." Thus my comment.

And as for my tone, I think it was warranted, given your behavior.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


yotam_k
Deleted

Mar 11, 2001, 12:36 AM

Post #20 of 24 (6820 views)
     Re: Delete all files from a dir . [In reply to]  

You know Japhy , I could continue argueing with you , Couse I Didn't said that jasmine has no Authority , I'd NEVER, N-E-V-E-R Said "mybe she has no authority" Becouse I am not blind you know , I can see neer here
Name The Icon Admin so please .
but I think this will have no use .

So I'll Say This , I learned Perl Myself , Starting from a Little Site in my language that teaches perl .

The knowledge I have Now I learned by myself , Using other programs and ETC.

I Can't complete the gaps I have Becouse All the books Are English ones And their heavy and I don't Understand anything .
So I come here and trying to ask some questions and then you think that some of my questions doesn't feet here , Ok , F... It but you lousey attemptes of kicking my out won't do , I'll continue to post here , but I'll promise I Will not post here simple questions .

Jasmin , I think That If someone has such a system he should predict that you will have good visitors and bad visitors , you can't send tham away , not in a good way in Geeky sentences and not by banning .

You should deal with them , not sending them to others , I'v chosen this website , don't send my to another .

Oh , And by the way , the thing I am working on is a Forum system that reminds this one , And I am working on a hebrew version , When I'll Finish the hebrew version and I'll make an english one , I'll send you to see it so you will see for what were all the efforts .







widexl
Novice

Mar 23, 2001, 4:13 PM

Post #21 of 24 (6802 views)
     Re: Delete all files from a dir . [In reply to]  

can't you just help?

Forget all the adavanced and begginer
just help without any calculations if it's relevant or not .

Jasmine , I think you will have alot of authority problems
mybe you don't have any authority I dont know .

Stop Being Such A goffy and geek

Please ???????????

Edited by japhy on 03/09/01 08:38 AM (server time).



Yes, yotam_k what you say is the true.
I have been starting with perl from notting.
And my script (Members Admin CGI) is my hello world.
I don't now many programmers who have make that kind of scripts when they are starting writing scripts.

The first mesage i have write in this forum (Advanced)
and Jasmine just moved it into the beginners forum. (I really hate that).
He don't even now how to delete all files from a dir (thats advanced).

I think to he have alot of authority problems
Or he is comming from the U.S.A. (then it's normal what he is doing).

then knows japhy a lot more!!!!
I hope that nobody edit this message.

Henk
Programmer off the Members Admin CGI




Jasmine
Administrator / Moderator

Mar 23, 2001, 9:25 PM

Post #22 of 24 (6798 views)
     Re: Delete all files from a dir . [In reply to]  

I won't justify your post with a detailed reply. Just post to the correct forum and your post won't be moved.


yotam_k
Deleted

Mar 29, 2001, 10:59 AM

Post #23 of 24 (6773 views)
     Re: Delete all files from a dir . [In reply to]  

Well I must thank henk on the support , jasmine , you should listen the man....

Yotam.



Jasmine
Administrator / Moderator

Mar 29, 2001, 11:48 AM

Post #24 of 24 (6771 views)
     Re: Delete all files from a dir . [In reply to]  

To even suggest that I should listen to such a rude person reflects poorly on yourself. I wouldn't go to your home and ignorantly insult you, your comrades, and for goodness sakes, your country. That's plain childish.

Remember, courtesy is king.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives