Sponsored Content
Top Forums Programming how to check if directory/file exist using c/c++ Post 94651 by vino on Monday 2nd of January 2006 11:39:27 PM
Old 01-03-2006
Use the stat call.

Code:
struct stat st;
if(stat("/tmp",&st) == 0)
        printf(" /tmp is present\n");

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to check if the file exist or not?

say i would like to check if the file is existed before i use rm command. How can i do it? i know if i can use find, but i would like to have a good interface (in a shell script) thks (3 Replies)
Discussion started by: gusla
3 Replies

2. Shell Programming and Scripting

how to check if directory/file exist using c/c++

Hi there,, how to check if directory/file exist using c/c++ under unix/linux? I can use access() under Window MFC. Thanks. Steven (1 Reply)
Discussion started by: steven88
1 Replies

3. Shell Programming and Scripting

Check if certain files exist in a directory, if not add name to a textfile

We recieve some logs on our windows box via FTP on a daily basis, in the same directory. I would like to check for missing logs files and add their name to a text file. Something like... Check if C:\logs\file1_currentdate exists (if not, add file1_currentdate to... (1 Reply)
Discussion started by: SunnyK
1 Replies

4. Shell Programming and Scripting

How to check directory exist on servers

There are many servers and their directory structer should be exactly the same. To check the directory path for all servers, I wrote a script. #! /bin/ksh ARRAY_DIRECTORIES="/c/dev/custom/bin" ARRAY_DIRECTORIES="/c/dev/db/custom/src" ARRAY_ENV="remoteName200" ARRAY_ENV="remoteName201"... (2 Replies)
Discussion started by: weonpc
2 Replies

5. Shell Programming and Scripting

To check whether a directory is exist and if it is not, create it

Hi, I want to write a shell script to check whether a directory (say A) is existing in a given location and if it is not, create it. (3 Replies)
Discussion started by: sabya
3 Replies

6. Shell Programming and Scripting

check the directory exist

I have the below script to check whether directory is exist or not , now I sure the directory /abc NOT exist , but when run the script , it still pop the result is "the directory exist" , could suggest what is wrong ? thx ll -d /abc > /dev/null 2>&1 if then echo "the directory exist !!" ... (7 Replies)
Discussion started by: ust
7 Replies

7. Shell Programming and Scripting

Check if file exist

Hi Does anybody know how I can check if a file exists i.e. see bellow, this doesn't work by the way and if tried countless variations on this file1=$one/file111.txt if then echo "Present" else echo "Not present" fi result : Not present (file is already present, eventhough its... (3 Replies)
Discussion started by: gksenthilkumar
3 Replies

8. Shell Programming and Scripting

Check if file exist

Hi, I am trying to create a bash script which will check if file exist then remove that file else do nothing. I have to do same process for three files in same script. I have written code for one file and trying to run it. if then rm -r /user1/abc/File1 fi When I run this code it... (1 Reply)
Discussion started by: palak08
1 Replies

9. Shell Programming and Scripting

Check if file exist

Hi, I created following script to check if file exist: #!/bin/bash SrcDir=$1 SrcFileName=$2 SrcTimePeriod=$3 if ;then echo 1 else echo 0 fi I ran it like: /apps/Scripts/FileExist.sh /apps/Inbox file1 2nd_period_2010 Even file exist at that location, my above command is... (4 Replies)
Discussion started by: palak08
4 Replies

10. Shell Programming and Scripting

how to check file exist in a directory or not

HI folks, can any one tell me how to check whether the file is existed in a directory or not . let me tell you my requirement : if the file is existed i should display a one message or else i have to send a mail .. i have the mail logic .. but I'm failed to check file existence .. please... (5 Replies)
Discussion started by: sravan008
5 Replies
IO::Async::File(3pm)					User Contributed Perl Documentation				      IO::Async::File(3pm)

NAME
"IO::Async::File" - watch a file for changes SYNOPSIS
use IO::Async::File; use IO::Async::Loop; my $loop = IO::Async::Loop->new; my $file = IO::Async::File->new( filename => "config.ini", on_mtime_changed => sub { my ( $self ) = @_; print STDERR "Config file has changed "; reload_config( $self->handle ); } ); $loop->add( $file ); $loop->run; DESCRIPTION
This subclass of IO::Async::Notifier watches an open filehandle or named filesystem entity for changes in its "stat()" fields. It invokes various events when the values of these fields change. It is most often used to watch a file for size changes; for this task see also IO::Async::FileStream. While called "File", it is not required that the watched filehandle be a regular file. It is possible to watch anything that stat(2) may be called on, such as directories or other filesystem entities. EVENTS
The following events are invoked, either using subclass methods or CODE references in parameters. on_dev_changed $new_dev, $old_dev on_ino_changed $new_ino, $old_ino ... on_ctime_changed $new_ctime, $old_ctime Invoked when each of the individual "stat()" fields have changed. All the "stat()" fields are supported apart from "blocks" and "blksize". Each is passed the new and old values of the field. on_devino_changed $new_stat, $old_stat Invoked when either of the "dev" or "ino" fields have changed. It is passed two File::stat instances containing the complete old and new "stat()" fields. This can be used to observe when a named file is renamed; it will not be observed to happen on opened filehandles. on_stat_changed $new_stat, $old_stat Invoked when any of the "stat()" fields have changed. It is passed two File::stat instances containing the old and new "stat()" fields. PARAMETERS
The following named parameters may be passed to "new" or "configure". handle => IO The opened filehandle to watch for "stat()" changes if "filename" is not supplied. filename => STRING Optional. If supplied, watches the named file rather than the filehandle given in "handle". The file will be opened for reading and then watched for renames. If the file is renamed, the new filename is opened and tracked similarly after closing the previous file. interval => NUM Optional. The interval in seconds to poll the filehandle using stat(2) looking for size changes. A default of 2 seconds will be applied if not defined. METHODS
$handle = $file->handle Returns the filehandle currently associated with the instance; either the one passed to the "handle" parameter, or opened from the "filename" parameter. AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::File(3pm)
All times are GMT -4. The time now is 07:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy