473,386 Members | 1,943 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,386 software developers and data experts.

Find::File error: Invalid Top Directory

hi, I have the following error on a win server:
"Invalid Top Directory perl/lib/file/find.pm line 598

Here's the code and I'll explain what I found until now:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #
  3. use strict;
  4. use warnings;
  5. use File::Find;
  6. use MSDOS::Attrib qw(get_attribs set_attribs);
  7.  
  8. (my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, my $yday, my $isdst)=localtime(time);
  9. $year = $year + 1900;           # $year 0 = real year 1900
  10. $mon = $mon + 1;                # $month 0 = January
  11.  
  12. open(LOG, ">>./atd_files_$year-$mon-$mday\.txt")  or die "Can't open LOG: $!";
  13. print LOG ("\n*****************************************      NEW LAUNCH      *****************************************\n") or die "Can't write to LOG: $!";;
  14. printf LOG " Script started at:\n %4d-%02d-%02d %02d:%02d:%02d\n\n", $year,$mon,$mday,$hour,$min,$sec or die "Can't write to LOG: $!";
  15.  
  16. my $homedir = "E:/test_dir";
  17. opendir (IMD, $homedir) or die "Couldn't find dir: IMD ($!)";
  18. my @thefiles= readdir(IMD);
  19. closedir(IMD);
  20.  
  21. my @dirs;
  22. my $x=0;
  23. my $n = 0;
  24.  
  25. foreach my $f (@thefiles){
  26.         if (-d $f && $f !~ /^\.+/){
  27.                 print "$f\n";
  28.                 $dirs[$x]=$f;
  29.                 $x++;
  30.         }
  31. }
  32.  
  33. #print "@dirs\n";
  34. find(\&wanted,  @dirs);
  35.  
  36. sub wanted {
  37.         if (/Project\.atd/){
  38.                 my $attrib = get_attribs($File::Find::name);    
  39.                 if ( $attrib =~ /.H.+/){            
  40.                         $n++;
  41.                         print "$File::Find::name\n";
  42.                 }
  43.         }
  44. }
  45.  
  46. print ("\n\nTotal: $n files\n");
  47.  
  48. print ("\a");
  49. ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(time);
  50. printf LOG "\n\n Script ended at:\n %4d-%02d-%02d %02d:%02d:%02d\n", $year+1900,$mon+1,$mday,$hour,$min,$sec or die "Can't write to LOG: $!";
  51. print LOG ("\n*****************************************      END LAUNCH      *****************************************\n") or die "Can't write to LOG: $!";
So, the problem is the $homedir

If I put "c:/blabla/blibli" as homedir, everything's ok.

I tested the same script on a 2000pro with "c:/balbla" and "d:/blabla" everything's ok.

But as soon as I put "E:/blabla" on the server, I got the error. Tested with different directories on E:, everytime I got an error. Not on C: or D:
anyone got an idea? (is it a bad thing to edit with Windows Notepad?? I usually use Jext)

Additional info:
I also got the error with
C:/ ; C:/ADMIN but not with C:/ADMIN/Analyst_Projectatd_RightsHidden

I'm totally lost now!!
Nov 16 '09 #1
11 7362
Another edit:
on my local machine, where everything was working, it didn't worked with
$homedir = "c:/" or eany other dir

But it works with $homedir = "c:"

Ok, well, I found another error in my script..
¨$homedir is not working at all.. except if $homedir = the directory where the script is located, then the script functions.

I also noticed a problem with Attrib..
When I do a print $attrib after the getattrib, it displays nothing :s
Nov 16 '09 #2
Another edit:
But it works with $homedir = "c:" (well, it doesn't work properly but it doesn't give an error)

I made a check: 15 target files, non hidden, all in log. Changed 1 to hidden.
The log still lists 15 files.

Could be two reasons:
- attrib function is not working properly
- the hidden attribute "H" is not in the second place as I saw on a site. But print $attrib should at least return something in stead of nothing..

I'm completely lost now.. Just a beginner, so maybe I use Find::File and MSDOS::Atrib wrong?? If you need more info, don't hesitate!
Nov 16 '09 #3
Update: (sorry about all those updates, but I continue searching)

about attrib..: attrib is working properly
it should be this:
Expand|Select|Wrap|Line Numbers
  1. my $myfile = "$homedir/$File::Find::name";
  2. my $attrib = get_attribs($myfile);
so, the only question left is the File::Find error (as stated in the subject ^^ )
Nov 16 '09 #4
RonB
589 Expert Mod 512MB
Your posts are all over the map with what is or isn't working and no detail on what changes you made to the script between those posts.

There are a number of problems with your script, but we'll start out with the"Invalid Top Directory" error.

Which var is it working on when you receive this error and exactly what is the value of that var?

Have you checked that the value it's referring to is actually a directory and that you have proper permissions to access that directory?
Nov 16 '09 #5
(If I could edit my posts after an hour, there wouldn't be 4 posts ^^)

So, every change I made has been detailed (changes of the $homedir var and changes of the Attrib part). I don't see what I forgot?

The value I'm working on for $homedir is actually a directory (not a mapped drive) and permissions have been set. I posted what worked and what not, and the reason I think why (may be completely wrong). What I understood so far is that the script is only working if the script is in the same directory as $homedir.

I never worked with File::Find before and it's a quite complete module and I just tried to understand what i needed to.

If you need any other info, shoot. I'm glad that someone who has the knowledge can show me the way.
Nov 17 '09 #6
RonB
589 Expert Mod 512MB
Lets start at the beginning and clean up the script.

Add this to the list of modules to load.
Expand|Select|Wrap|Line Numbers
  1. use POSIX qw(strftime);
Change this:
Expand|Select|Wrap|Line Numbers
  1. (my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, my $yday, my $isdst)=localtime(time);
  2. $year = $year + 1900;           # $year 0 = real year 1900
  3. $mon = $mon + 1;                # $month 0 = January
  4.  
  5. open(LOG, ">>./atd_files_$year-$mon-$mday\.txt")  or die "Can't open LOG: $!";
  6. print LOG ("\n*****************************************      NEW LAUNCH      *****************************************\n") or die "Can't write to LOG: $!";;
  7. printf LOG " Script started at:\n %4d-%02d-%02d %02d:%02d:%02d\n\n", $year,$mon,$mday,$hour,$min,$sec or die "Can't write to LOG: $!";
  8.  
To this:
Expand|Select|Wrap|Line Numbers
  1. my $logfile = strftime("atd_files_%Y-%m-%d.txt", localtime);
  2. open my $LOG, '>>', $logfile or die "Can't open <$logfile> $!";
  3.  
  4. print $LOG "\n", '*' x 25, '      NEW LAUNCH      ', '*' x 25, "\n";
Get rid of this unnecessary and inefficient code (which is the source of your problem).
Expand|Select|Wrap|Line Numbers
  1. opendir (IMD, $homedir) or die "Couldn't find dir: IMD ($!)";
  2. my @thefiles= readdir(IMD);
  3. closedir(IMD);
  4.  
  5. my @dirs;
  6. my $x=0;
  7. my $n = 0;
  8.  
  9. foreach my $f (@thefiles){
  10.         if (-d $f && $f !~ /^\.+/){
  11.                 print "$f\n";
  12.                 $dirs[$x]=$f;
  13.                 $x++;
  14.         }
  15. }
And change your call to the find function to this:
Expand|Select|Wrap|Line Numbers
  1. find(\&wanted,  $homedir);
Change this:
Expand|Select|Wrap|Line Numbers
  1. ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(time);
  2. printf LOG "\n\n Script ended at:\n %4d-%02d-%02d %02d:%02d:%02d\n", $year+1900,$mon+1,$mday,$hour,$min,$sec or die "Can't write to LOG: $!";
  3. print LOG ("\n*****************************************      END LAUNCH      *****************************************\n") or die "Can't write to LOG: $!";
To this:
Expand|Select|Wrap|Line Numbers
  1. print $LOG strftime("\n\n Script ended at:\n %Y-%m-%d %H:%M:%S\n", localtime),
  2.            "\n", '*' x 25, '      END LAUNCH      ', '*' x 25, "\n";
Nov 17 '09 #7
Well, all I have to say is .. thank you very much!!!!

It works great and the script is 2x smaller.
And POSIX strftime is easier to work with than the other one.

And I also learned new things about logging and the print command!
Thanks again!!! This is what I call a great answer to a problem ^^
Nov 18 '09 #8
RonB
589 Expert Mod 512MB
@ezechiel
You're welcome.

The wanted sub could be cleaned up a little, but it's not too bad, so I left it alone.

But if you're interested, here's the cleaned up version.
Expand|Select|Wrap|Line Numbers
  1. sub wanted {
  2.     return unless /Project\.atd/;
  3.  
  4.     my $hidden = substr(get_attribs($File::Find::name), 1, 1);    
  5.  
  6.     if( $hidden eq 'H' ) {
  7.         $n++;
  8.         print "$File::Find::name\n";
  9.     }
  10. }
Nov 18 '09 #9
ok, thanks for the info. I'll check out the substr() function.

About this one:
Expand|Select|Wrap|Line Numbers
  1. open my $LOG, '>>', $logfile or die "Can't open <$logfile> $!";
Don't I need to close the log at the end? I suppose it is like this?:
Expand|Select|Wrap|Line Numbers
  1. close $LOG;
Nov 19 '09 #10
RonB
589 Expert Mod 512MB
Filehandles that use a lexical var instead of a bareword will automatically close when they go out of scope. However, it is best practice to explicitly close them when they are no longer needed.
Nov 19 '09 #11
ok,
thanks for all this precious info Ron ;)
It helped me a lot!
Nov 20 '09 #12

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

Similar topics

0
by: Joe Hershman | last post by:
all, not sure what the best place to post this one, hopefully someone can help because this is a real show stopper. i am getting the error shown below when i try to build a deployment project. ...
3
by: Brian Fulford | last post by:
I am trying to deploy a web app with a deployment project since I am including Crystal Reports for .Net. I attached all the merge modules, etc but I am getting a build error when I try to build...
2
by: jlacefie | last post by:
Hello, I am having trouble with the following code using ASP.Net 2.0. I recieve an error on the line File.OpenRead(fPath) stating could not find file . The fPath comes from a textbox control...
1
by: dereski | last post by:
Hey all, I am trying to connect to my database but I am getting error "80004005 Could Not Find File" Any Ideas as to why? I tried recreating the database again, just in case it was corrupted...
3
by: Amritha.Datta | last post by:
Can anyone tell me why the below code returns error? Exception Details: System.IO.FileNotFoundException: Could not find file Dim strLFolder As String = "c:\Temp\F Files" Dim intClientID As...
2
by: jjlagtap | last post by:
Hey everyone When I try to open a file i get the Exception listed below. The weird thing is it works when I run the web app locally and when i use a remote server and open a file on my computer....
0
by: chandan | last post by:
Hi All, I am creating a web setup Project using VS 2005.First time its works fine, But when I closed the solution and again open solution and try to build web setup project then there is an error...
6
by: =?Utf-8?B?U2NvdHQgVHJpY2s=?= | last post by:
I followed the instructions from MSDN for Webclient UploadFile and I get an error: Could not find file 'C:\testfile.xls'. If I add the file (c:\testfile.xls) to the server I do not get the error...
6
JustRun
by: JustRun | last post by:
I have two windows application projects in the same solution, The solution contains an application that has a reference to another application in the same solution, When I tried to publish the...
0
JustRun
by: JustRun | last post by:
Hi All This is a very urget, Plz answer me I have two windows application projects in the same solution, The solution contains an application that has a reference to another application in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.