473,480 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Directory access

8 New Member
How can I open a directory and check if the content inside has another directory .If there is a directory, I want it to be opened again and again checked for any other directory.This process has to be repeated till it reaches a folder called "STAGING". Then the script generates the absolute path till the parent directory of STAGING.
Oct 5 '06 #1
8 3127
deep022in
23 New Member
How can I open a directory and check if the content inside has another directory .If there is a directory, I want it to be opened again and again checked for any other directory.This process has to be repeated till it reaches a folder called "STAGING". Then the script generates the absolute path till the parent directory of STAGING.

########


I have partial solution to your problem

you can verify whether the directory contains subdirectory by the following code

Expand|Select|Wrap|Line Numbers
  1. opendir(DIR1,"?home/xyz");
  2. while(my $dir = readdir(DIR1))
  3. {
  4. if( -d $dir)
  5. {
  6. print "$dir is subdirecotry\n";
  7. }
  8. }
  9. closedir(DIR1);
  10.  
let me know if this helped you

regards,
deep
Oct 5 '06 #2
heto
1 New Member
How can I open a directory and check if the content inside has another directory .If there is a directory, I want it to be opened again and again checked for any other directory.This process has to be repeated till it reaches a folder called "STAGING". Then the script generates the absolute path till the parent directory of STAGING.
For Windows in my mind comes a quick trick - command "dir"

A little example:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. #define variables
  3. my ($path) = @ARGV;
  4. my $absolutePath; 
  5.  
  6. #open virtual file -> see dir /?
  7. open(DIR, "dir $path /A:D /S /B|");
  8.  
  9. #until end of file do something
  10. while(<DIR>){
  11.  if(/STAGING/){
  12.  $absolutePath = $_; #set your needed value
  13.  last; #end the while, we found what we want
  14.  }
  15. }
  16.  
  17. #print result
  18. print $absoultePath;
  19.  
this example works only for windows

for linux is command "ls", but i don't have too much experience with unix/linux systems.

Other way is to use a recursive function with opendir, chdir and verify if the name is what we are looking for. The problem there is that we look into a matrix and you have to determinate how to look(depth or breadth), it's a little more complicate. If this example doesn't suite you, and you didn't get your answer yet, please let a note and i will try to find time to write the recursive example for you.
Oct 14 '08 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
deep and heto,

Both of you need to please remember to use code tags to enclose ANY code that you post into the forums. If you don't do it, the moderators, like myself, must come in after you and clean up. We really prefer it if you add them during your posting. If you don't know how to use them, take a look at the "Reply Guidelines" box to the right of your reply window when replying.

Regards,

Jeff
Oct 14 '08 #4
KevinADC
4,059 Recognized Expert Specialist
And you all need to check the thread dates:

October 5th, 2006

3 months is an old thread, 2+ years is ancient history.
Oct 14 '08 #5
eWish
971 Recognized Expert Contributor
Well that is one less unanswered question. :-)

--Kevin
Oct 14 '08 #6
KevinADC
4,059 Recognized Expert Specialist
Well that is one less unanswered question. :-)

--Kevin
The better perl solution is to use File::Find and exit() when the file/folder is found.
Oct 14 '08 #7
gaurav1086
4 New Member
hi ther.e.. i am a newcomer to perl so all i can give is an algorithm for ur solution if u like implement it. and let me know if it helped.
the algo goes like this____
you have to go on opening directories recursively.,with the exit condition.that (until a directory with a particular name is reached.)
and then do the backtracking.. to see.. if there.. are more files in the directory..
all you have to imagine is that.. its like a tree structure that..contains parents(of any subinstance as the parent directory) and its children as the subdirectories.
i think its going to work.. plz let me know if it does..
Oct 16 '08 #8
KevinADC
4,059 Recognized Expert Specialist
hi ther.e.. i am a newcomer to perl so all i can give is an algorithm for ur solution if u like implement it. and let me know if it helped.
the algo goes like this____
you have to go on opening directories recursively.,with the exit condition.that (until a directory with a particular name is reached.)
and then do the backtracking.. to see.. if there.. are more files in the directory..
all you have to imagine is that.. its like a tree structure that..contains parents(of any subinstance as the parent directory) and its children as the subdirectories.
i think its going to work.. plz let me know if it does..
File::Find already does this. Please note you have posted in a thread that is more than two years old.
Oct 16 '08 #9

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

Similar topics

0
772
by: Tom Youngquist | last post by:
I have two .NET sits (one is intranet and one internet). One of the "subdirectories" in the internet site I would like to include in my intranet site. I have created a "vertual directory" through...
2
3374
by: Jamie Bissett | last post by:
I cannot find ant doc to indicate how to access the user selected installation directory during the install process. I am trying to update the application confiduration file based upon some of the...
2
4367
by: Annette Massie | last post by:
Is there a way to find the names of users in an Active Directory WWW group?
0
1164
by: Dominic | last post by:
I got the following error when I built a project. vcdeploy : error VCD0035: Failed to create the file system directory for the virtual directory. Access is denied. The project / properties /...
1
1222
by: Len Svitenko | last post by:
I have a site in asp.net. In that site I have a directory full of excel spreadsheets. When a user logs in it points them to the spreadsheet that I want them to see. However, if they then exit...
2
1300
by: Hari | last post by:
Hi I have an ASP.NET application that writes to a log file in a directory outside the webapp directory (e.g. c:\program files\myapp\logs). OS is Windows 2003 If I see the list of users in the...
2
2207
by: web02 | last post by:
Hi y'all, It has been a long time and suddenly, I have a VC98 compiler with which I need to determine all the files in a directory and its subdirectories. I forget the functions available for...
2
1615
by: mark babli | last post by:
how can I access a remote (linux) directory using php?
0
1246
by: eholz1 | last post by:
Hello PHP group, I have a question about file locations, and whether on not (in my case, not) a page will execute depending on the location of the php file. I have a web devel server, with a...
1
1838
by: jyohere | last post by:
How to access a remote machine directory from a local machine....I tried something like this: opendir(DIR,"192.168.9.62:/home/cygnet/Marconi_PM_Simulator/conf/"); @files = readdir(DIR); ...
0
7037
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
6904
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
7076
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...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6873
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...
1
4767
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...
0
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.