473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Tree scanning doesnt work

2
Hello,

Ive written a perl script which should tree scan all my directories and print each passing file.. the problem is that after the first directory it enters some dots after the slash..
can you please tell me where is my mistake.. thanks for your help

(P.S i know that there is such a module however i prefer writing it by myself)

Expand|Select|Wrap|Line Numbers
  1. #! c:\perl\perl.exe
  2. use strict;
  3.  
  4. sub dir_tree {
  5.     my $dirr = shift;
  6.     print "The current directory: $dirr \n";
  7.     opendir (IN,$dirr) || die "Couldnt Open $dirr : $!\n";
  8.     while (my $current_file = readdir IN) {    
  9.  
  10.         if (-d "$dirr\\$current_file" ) {
  11.             print "Entering $dirr$current_file\\\n"; <STDIN>;
  12.             &dir_tree("$dirr$current_file\\");
  13.         }
  14.  
  15.         print "$dirr$current_file\n";
  16.     }
  17. }
  18.  
  19. print "Enter the destination directory with \ in the end \n";
  20.  
  21. my $dir = <STDIN>;
  22. chomp $dir;
  23.  
  24. &dir_tree($dir);
  25.  
  26.  
Mar 3 '07 #1
5 1482
KevinADC
4,059 Expert 2GB
the first two files in any directory is '.' and '..' you need to filter them out. Not sure why you have <STDIN> on this line:

Expand|Select|Wrap|Line Numbers
  1. print "Entering $dirr$current_file\\\n"; <STDIN>; 
Mar 3 '07 #2
mugen8
2
thanks it has worked

the stdin was for debugging purposes
Mar 3 '07 #3
KevinADC
4,059 Expert 2GB
I know it's fun to do in perl and has it's benefits, but this is is also easy using the OS:

Expand|Select|Wrap|Line Numbers
  1. my @files = qx/dir c:\/startdir \/S \/B/;
the array will now have a list all files in all sub folders in c:\startdir
Mar 3 '07 #4
ghostdog74
511 Expert 256MB
I know it's fun to do in perl and has it's benefits, but this is is also easy using the OS:

Expand|Select|Wrap|Line Numbers
  1. my @files = qx/dir c:\/startdir \/S \/B/;
the array will now have a list all files in all sub folders in c:\startdir
it's not cross platform though.
Mar 4 '07 #5
KevinADC
4,059 Expert 2GB
it's not cross platform though.
to quote myself:

know it's fun to do in perl and has it's benefits... ;)
Mar 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: David | last post by:
I have a simple tree structure where node x can have y children. Node x's children are stored in an array. I want to supply a node to a function and count the TOTAL number of children for that...
1
by: pentiumPunk | last post by:
Lets say i have a binary tree that looks like this: root -> O O <--- one of the nodes i need nodeValue's for ---> O
7
by: Casper | last post by:
In scanning a drive and comparing file content, I need to remember filepaths to every single file I encounter so I can take actions on certain files later on. Rather than having a huge list...
2
by: dannielum | last post by:
Hi all, I am trying to write a Binary Search Tree that each of its node will have 3 node pointers: left, right and parent. I need a parent pointer for some the purpose of my project. Without the...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
25
by: prabhat143 | last post by:
Hi, Given a singly linked, null terminated list, how can it be converted to tree? Each node in the list has three attributes: it's ID, it's parent ID and of course, the next node it's pointing...
4
by: contactme.navin | last post by:
Hi, I have problem in displaying the treeview in my asp pages. I had used the obout.com tree view to display the tree navigation in the webpages. Following is the error i got in the page....
4
by: shuisheng | last post by:
Dear All, I'd like to build a structure similar to the folder tree which 1. Has a root. 2. Nodes can be folder or files. 3. Folder can contain folders and files. 4. Name of folders and files...
12
by: Chris | last post by:
Are there any other controls which could replace List & Tree controls, because they have limitation of accepting only 32767 items. thanks a lot in advance.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.