Re: Need a list of files in a dir.
Hello , in your examples you're opening files not dir's , to open a directory use this instead opendir(DIR,$dirname) or die $!; my @content = readdir(DIR); closedir(DIR); then to read files inside it , for (@content){ print ; } that's it , if you need to remove (. and ..) which means the top directorys most of time use it as follow : opendir(DIR,$dirname) or die $!; my @content = grep {! /^\./},readdir(DIR); closedir(DIR); then again read them using for (@content){ print; } That's it HTH On 9/26/05, Tom Allison [EMAIL PROTECTED] wrote: Wiggins d'Anconia wrote: Please bottom post... Daniel Kurtz wrote: Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Well, there's two methods that I use where I can and they are probably more portable. glob works well most of the time: @files = /directory/goes/here/*; But it has problems with large numbers of files. And the problems will cause it to fail badly. The other is to opendir and read in a loop. In either case you need to remove the '.' and '..' entries: @files = grep {! /^\./} /directory/goes/here/* or something like that. I should warn you, not only is this untested code, but I haven't even had my coffee yet. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Wiggins d'Anconia wrote: Please bottom post... Daniel Kurtz wrote: Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Well, there's two methods that I use where I can and they are probably more portable. glob works well most of the time: @files = /directory/goes/here/*; But it has problems with large numbers of files. And the problems will cause it to fail badly. The other is to opendir and read in a loop. In either case you need to remove the '.' and '..' entries: @files = grep {! /^\./} /directory/goes/here/* or something like that. I should warn you, not only is this untested code, but I haven't even had my coffee yet. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Ryan == Ryan Frantz [EMAIL PROTECTED] writes: Ryan I don't think that Randal was arguing that there are more UNIX vs. Ryan Windows systems as much as he was stating that given a number of UNIX Ryan systems vs. Windows systems, more UNIX systems have Perl Ryan implementations. I *was* saying what I think you said I wasn't saying, so let me say it again another way: The number of Unix (or unix-like, like Linux or Mac OSX) systems that have Perl installed is (far?) greater than the number of Windows (like? :) system that have Perl installed. I believe that to be true, in fact probably by at least a factor of five or ten to one. Perl is still most at home in the Unix world. Consider that OSX plus nearly every flavor of Linux and *BSD come with Perl installed, but every installation of Windows is Perl-free until someone heads off on their own to activestate.com. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Daniel -Original Message- From: Luinrandir [mailto:[EMAIL PROTECTED] Sent: Thursday, August 25, 2005 21:33 To: beginners@perl.org Subject: Need a list of files in a dir. How do I get the list of files in a DIR and put in an array? I'm drawing a blank on my search for this. thanks Lou -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Please bottom post... Daniel Kurtz wrote: Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Sort of, while that *may* work it doesn't have proper error checking, is less secure, less efficient, and less portable than many other ways, especially those already provided. This is my same rant as in the past, check the archives if you want the real details, but shelling out is an *absolute* last resort. Perl provides built-in functions to handle this, in cases where it does it is never faster, safer, or more portable to shell out. http://danconia.org Daniel -Original Message- From: Luinrandir [mailto:[EMAIL PROTECTED] Sent: Thursday, August 25, 2005 21:33 To: beginners@perl.org Subject: Need a list of files in a dir. How do I get the list of files in a DIR and put in an array? I'm drawing a blank on my search for this. thanks Lou -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
-Original Message- From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, August 26, 2005 11:27 AM To: Daniel Kurtz Cc: beginners@perl.org Subject: Re: Need a list of files in a dir. Please bottom post... Daniel Kurtz wrote: Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Sort of, while that *may* work it doesn't have proper error checking, is less secure, less efficient, and less portable than many other ways, especially those already provided. I agree. Though I'm still a novice, I have already applied Perl scripts to several tedious tasks that I have. These include searching file systems for this, that, and the other file. A good resource is O'Reilly's Perl for System Administration, Ch. 2 Filesystems. In demonstrates modules such as Cwd and File::Find that work great in scouring your filesystem. And of course, don't forget to search CPAN; lots of good stuff. This is my same rant as in the past, check the archives if you want the real details, but shelling out is an *absolute* last resort. Perl provides built-in functions to handle this, in cases where it does it is never faster, safer, or more portable to shell out. http://danconia.org Daniel -Original Message- From: Luinrandir [mailto:[EMAIL PROTECTED] Sent: Thursday, August 25, 2005 21:33 To: beginners@perl.org Subject: Need a list of files in a dir. How do I get the list of files in a DIR and put in an array? I'm drawing a blank on my search for this. thanks Lou -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
-Original Message- From: Luinrandir [mailto:[EMAIL PROTECTED] Sent: Friday, August 26, 2005 2:53 PM To: Daniel Kurtz Cc: beginners@perl.org Subject: Re: Need a list of files in a dir. Thanks Daniel.. and keep on TOP POSTING! Not to start a flame war, but it has been established on this list that in-line (not bottom-) posting is preferred. I was once instructed (not forced) to do so on this list as I primarily top-post most emails (as many people do). There are several arguments in both camps but that discussion is outside the scope of this list. To sum things up: be adaptable, man! A protocol has been established on this list. Let it be known here and now (maybe it should be in the list FAQ, if it isn't already). Don't waste time (speaking from experience) with top post/in-line post/bottom post propaganda. ry It is best to remain quiet and thought a fool, than to open one's mouth and remove all doubt. -Grandpap Gawd I hate bottom posting! Lou Hernsen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Thanks Daniel.. and keep on TOP POSTING! Gawd I hate bottom posting! Lou Hernsen (.. and so my children the war between the topposters and bottomposters began The topposters, light happy and joyous beings ; the bottomposters, smelly and scragly and living below the earth in tunnels and caves in the land of Scorch... shaking there fists at the top posters. Oh.. they thought quietly to themselves, if WE could as free as you. But since we don't wanna, we will taunt you, and scold you and try to make you like us. And the children of the top posters went on top posting. One day some of the newer top posters were throwing bread crumbs into the holes in the earth that lead to the caverns of the bottom posters when suddenly... a butterfly flew by and the children of the topposters followed it, happy and dancing and holding hands and not listening to the grumblings, coming from the holes in the ground, that lead to the caverns of the bottomposters in the land of Scorch... who lived unhappily ever after..) - Original Message - From: Daniel Kurtz [EMAIL PROTECTED] To: beginners@perl.org Sent: Friday, August 26, 2005 8:12 AM Subject: RE: Need a list of files in a dir. Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Daniel -Original Message- From: Luinrandir [mailto:[EMAIL PROTECTED] Sent: Thursday, August 25, 2005 21:33 To: beginners@perl.org Subject: Need a list of files in a dir. How do I get the list of files in a DIR and put in an array? I'm drawing a blank on my search for this. thanks Lou -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Daniel Kurtz wrote: Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Please tell me you're kidding. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
-Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED] Sent: Friday, August 26, 2005 9:40 AM To: Daniel Kurtz; beginners@perl.org Subject: Re: Need a list of files in a dir. Daniel Kurtz wrote: Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Please tell me you're kidding. -- This may be closer to what you want: opendir(DIR, $somedir) or die cannot opendir $somedir: $!; while (defined($somefile = readdir(DIR))) { # process $somedir/$somefile } closedir(DIR); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
Bob Showalter wrote: Please tell me you're kidding. Why? It works. The question asked how you can do it, not the BEST way to do it. And after a week of Perling, this was the one way I knew. Now I know two ways. g daniel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Daniel == Daniel Kurtz [EMAIL PROTECTED] writes: Daniel Why? It works. Not on Unix it doesn't. And there are far more Unix installations of Perl than Windows installations of Perl. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
From: Randal L. Schwartz [mailto:[EMAIL PROTECTED] Daniel Why? It works. Not on Unix it doesn't. And there are far more Unix installations of Perl than Windows installations of Perl. Good point. Although... while I'm certain that a higher PERCENTAGE of Unix systems have Perl than Windows systems do, are we certain that translates to a higher NUMBER of systems? Not that I'm trying to start an OS/religious flamewar. Now that I think about it, I just find it an interesting question. daniel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
-Original Message- From: Daniel Kurtz [mailto:[EMAIL PROTECTED] Sent: Friday, August 26, 2005 3:49 PM To: beginners@perl.org Subject: RE: Need a list of files in a dir. From: Randal L. Schwartz [mailto:[EMAIL PROTECTED] Daniel Why? It works. Not on Unix it doesn't. And there are far more Unix installations of Perl than Windows installations of Perl. Good point. Although... while I'm certain that a higher PERCENTAGE of Unix systems have Perl than Windows systems do, are we certain that translates to a higher NUMBER of systems? Not that I'm trying to start an OS/religious flamewar. Now that I think about it, I just find it an interesting question. I don't think that Randal was arguing that there are more UNIX vs. Windows systems as much as he was stating that given a number of UNIX systems vs. Windows systems, more UNIX systems have Perl implementations. daniel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Daniel Kurtz wrote: Bob Showalter wrote: Please tell me you're kidding. Why? It works. The question asked how you can do it, not the BEST way to do it. And after a week of Perling, this was the one way I knew. Now I know two ways. g OK, you weren't kidding. Since you're new to Perl, you get a free pass :~) Seriously, though, not all of us run Perl on Windows. Your approach is Windows-specific. In addition, the dir command outputs a bunch of other stuff besides the file name, so you'd have to do some parsing to get the file names. Either a glob approach or an opendir/readdir approach is simpler and more portable if one just needs a list of file names. If more details are needed, the stat() function (or related operators) can be applied to the resulting list. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need a list of files in a dir.
From: Bob Showalter [mailto:[EMAIL PROTECTED] OK, you weren't kidding. Since you're new to Perl, you get a free pass :~) I appreciate the indulgence g. Seriously, though, not all of us run Perl on Windows. Your approach is Windows-specific. True, I hadn't thought of that. I'm primarily a Visual Studio person, and the biggest point of platform variation we need to worry about in our discussion forums is usually Are you using Service Pack 4 or Service Pack 5? In addition, the dir command outputs a bunch of other stuff besides the file name, so you'd have to do some parsing to get the file names. Actually, use the /b switch and you do get just the file names. I agree now that Perl gives you easier ways to do it (actually, I pretty much assumed that was the case all along, I just hadn't had time yet to find out what those other 'proper' ways were.) daniel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Need a list of files in a dir.
How do I get the list of files in a DIR and put in an array? I'm drawing a blank on my search for this. thanks Lou -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
On Thu, 25 Aug 2005, Luinrandir wrote: How do I get the list of files in a DIR and put in an array? I'm drawing a blank on my search for this. Try writing a program instead, that seems to work better than drawing. Some people use globs in their programs for this. What did you try? -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Luinrandir wrote: How do I get the list of files in a DIR and put in an array? perldoc -f opendir perldoc -f readdir perldoc -f glob John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Thanks.. I'll look it over Lou - Original Message - From: John W. Krahn [EMAIL PROTECTED] To: Perl Beginners beginners@perl.org Sent: Thursday, August 25, 2005 6:26 PM Subject: Re: Need a list of files in a dir. Luinrandir wrote: How do I get the list of files in a DIR and put in an array? perldoc -f opendir perldoc -f readdir perldoc -f glob John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Your a funny dude Chris. On 8/25/05, Chris Devers [EMAIL PROTECTED] wrote: On Thu, 25 Aug 2005, Luinrandir wrote: How do I get the list of files in a DIR and put in an array? I'm drawing a blank on my search for this. Try writing a program instead, that seems to work better than drawing. Some people use globs in their programs for this. What did you try? -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response