Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Null and Void

Testing for file or path

This topic is 6088 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Hi,

I didn't understand what you want :-). Can you elaborate :-).

Well I am shooting arrows in the dark, but you might be looking for opendir(char *name); function :-).

man opendir

BTW from the title - generally in shell scripts one would do it like test -f filename - it would test for file and test -d $PATH would test for directory. Not sure if this is what you want to do, but ofcourse this isn't c/c++.



Edited by - flame_warrior on September 22, 2001 3:35:37 AM

Share this post


Link to post
Share on other sites
When you say you have a string with a path/file name in it, what exactly do you mean?

(elaborate)

After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

Share this post


Link to post
Share on other sites
Well, I think I found a way to do it using the "stat" function, but I''m not sure since I haven''t tested it. Basically, I have a string like this "/home/Someone/fish" and I don''t know whether or not the ''file'' /home/Someone/fish is a directory or a actual file.

I''m trying to write a crossplatform wrapper for things like getting a list of directories and files, creating links, hiding the / (*nix), \ (DOS/Windows), or : (MacOS 9) path styles, et cetera.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
In Unix, everything is a file. Directories, sockets, processes, pipes - they''re all files. So the distinction between a directory and a file is simply an attribute. The unix shell supports a command -d that returns true if the specified file is a directory:

if( -d $file )
{
//... do whatever
}

Perl also supports that syntax. I don''t know which functions return file attributes, but you want to find out whether the "directory" bit is set. Worst case scenario, I think you can do

sprinf( buffer, "-d %s", file ); // correct syntax. i don''t use this function
system( buffer );

Type ''man system'' to find out what headers to include and what libraries to link with.

Share this post


Link to post
Share on other sites
What''s with that last post inverting my smiley ? Anyway, the stat function did what I wanted. I finished writing the basics library for both Win32 and Linux, hopefully sourceforge lets me post it there with some really simple documentation in a few days. I''m releasing it under the ZLib license, since it is so small that I don''t care a whole lot what people do with it .

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!