Wednesday, August 8, 2007

Directory Access && File and Directory Manipulation (Part 8)-- Perl Study Notes

Directory Access && File and Directory Manipulation (Part 8)-- Perl Study Notes

 Change Directory Tree
  chdir($dirpath);
  #here is the example
  print "where do you want to go?"
  chomp($toPath=<STDIN>);
  if(chdir $where){
   # we got there
   }
   else
   {
   # we cannot go there
   }
 
 Globing
  <$pattern>; #In array context, it returns all files, the folder as well, matched the pattern. In scalar context, it returns the next file name it matched the pattern

  glob($pattern); #it is equivalent to <$pattern>
  @a=<c:/temp/*>; #it returns all file lists
  @a=glob("c:/temp/*); # same as above
  while ($filename=<c:/temp/*>) # return the next filename, the folder as well, in each iteration
  {
    print "one of the file name is $filename";
  }
 
   while ($filename=glob("c:/temp/*") # return the next filename, the folder as well, in each iteration
  {
    print "one of the file name is $filename";
  }
 
  #pls be notes although file blobbing and regular-expression matching function similarly
  #the meaning of the various special characters in quite different
  #the *,[] can be used in the pattern
 
 Directory Handlers
  opendir(DirectoryHandler,$pathname);
  readdir(DirectoryHandler); #in array context, it returns all fills , the folder as well, under the path. in scalar context, it returns the next file(folder) name under the path

  closedir(DirectoryHandler);

No comments: