09-03-2009
Perl file and folder listing -Help
Hello,
I want to display all files and folders in a drive under windows. I tried two ways.
1-Way Here is the code snippet.
opendir DIR, "F:\"; # Searching under F drive
my @files = readdir(DIR); # Reading eveythg under F drive
closedir DIR; # closeing the directory handler
foreach my $file (@files) {
print "This is file $file \n" if (-f $file);
print "This is folder $file \n" if (-d $file);
}
Result :It is not listing anythg.I think it cant differentiate files and folders,It will work under UNIX not in WINDOWS .
2-Way Code snippet.
$value = "F:/*\.*"; # Searching under F drive
@files = <"$value">;
foreach my $file (@files) {
print "Here is the content of the drive $file ";
}
Result :Here nothg got displayed.
Please help..
Thanks in advance
Coolbhai
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies
2. Shell Programming and Scripting
i will tell my problem with example:
if i have a folder name called sree1.7.3
i know the starting name say sree and also path say /usr/lib.
so i want the folder name.
and how can i link this folder in makefile
thank u
sree (2 Replies)
Discussion started by: phani_sree
2 Replies
3. Shell Programming and Scripting
Hi,
I have a requirement to move a file from one folder(a) to another folder(b) only when folder (b) have a write permission. Folder permission is 755
If the permission is otherthan 755 we need to come out of the loop
I will appreciate your help
Thanks
Soll (1 Reply)
Discussion started by: sollins
1 Replies
4. Shell Programming and Scripting
This is the file structure:
DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg
DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg
DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg
DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg
DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies
5. Shell Programming and Scripting
Hi all,
let me explain my requirments
i am having 5 folder with different name for eg) abc , cdf , efd, rtg, ead
each 5 folders contain 15 files
i want to move 10 files to some other folder, remain 5 files should be there in the same folder.
give me some suggestion on this. (6 Replies)
Discussion started by: natraj005
6 Replies
6. UNIX for Dummies Questions & Answers
Hi All,
Could you please help to resolve my following issues:
Problem Description:
Suppose my user name is "MI90".
i.e. $USER = MI90
when i run below command, i get all the processes running on the system containing name MQ.
ps -ef | grep MQ
But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies
7. Shell Programming and Scripting
Greetings everyone.
I have seen that you do wonders here.
I have a large folder on a Ubuntu linux.
Organization main folder, inside 20 000 subfolders, and inside those subolders many other like 5-6 folders and files.
I am interested to create an output to a txt file under the bash... (2 Replies)
Discussion started by: ultimo
2 Replies
8. Programming
Hi
I'm trying to look through a series of directories in A folder, lets just call it A:
for example:
A/1
A/2
A/3
Etc and I wish to move the files in the folder if they are bigger than a certain size into a structure like below:
A/TooBig/1
A/TooSmall/1
A/TooBig/2
A/TooSmall/2... (1 Reply)
Discussion started by: PerlNewbRP
1 Replies
9. Shell Programming and Scripting
Hi,
I'm looking for a Perl module which can recursively list remote Windows shares from within a Linux machine.
I've tried Filesys::SmbClient ans Filesys:SmbClientPars but they just list the current directory
Thank You for your help (4 Replies)
Discussion started by: Fundix
4 Replies
10. Shell Programming and Scripting
Is there anything i can do about this code? I need to sort it by folder creation, the newest will be first ... thx :)
for dirname in postme:
dirname = os.path.abspath(dirname)
if dirname:
... (2 Replies)
Discussion started by: ZerO13
2 Replies
DIRECTORY(3) Library Functions Manual DIRECTORY(3)
NAME
opendir, readdir, telldir, seekdir, rewinddir, closedir - directory operations
SYNOPSIS
#include <sys/types.h>
#include <sys/dir.h>
DIR *opendir(filename)
char *filename;
struct direct *readdir(dirp)
DIR *dirp;
long telldir(dirp)
DIR *dirp;
seekdir(dirp, loc)
DIR *dirp;
long loc;
rewinddir(dirp)
DIR *dirp;
closedir(dirp)
DIR *dirp;
DESCRIPTION
Opendir opens the directory named by filename and associates a directory stream with it. Opendir returns a pointer to be used to identify
the directory stream in subsequent operations. The pointer NULL is returned if filename cannot be accessed, or if it cannot malloc(3)
enough memory to hold the whole thing.
Readdir returns a pointer to the next directory entry. It returns NULL upon reaching the end of the directory or detecting an invalid
seekdir operation.
Telldir returns the current location associated with the named directory stream.
Seekdir sets the position of the next readdir operation on the directory stream. The new position reverts to the one associated with the
directory stream when the telldir operation was performed. Values returned by telldir are good only for the lifetime of the DIR pointer
from which they are derived. If the directory is closed and then reopened, the telldir value may be invalidated due to undetected direc-
tory compaction. It is safe to use a previous telldir value immediately after a call to opendir and before any calls to readdir.
Rewinddir resets the position of the named directory stream to the beginning of the directory.
Closedir closes the named directory stream and frees the structure associated with the DIR pointer.
Sample code which searchs a directory for entry ``name'' is:
len = strlen(name);
dirp = opendir(".");
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
closedir(dirp);
return FOUND;
}
closedir(dirp);
return NOT_FOUND;
SEE ALSO
open(2), close(2), read(2), lseek(2), dir(5)
4.2 Berkeley Distribution September 24, 1985 DIRECTORY(3)