QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Directory Checking Code

This is a discussion on Directory Checking Code within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I want code that checks for a dir. then apply a functions due to the availability of that dir. How ...

Reply
 
LinkBack Thread Tools
Old 11-25-2006, 09:18 AM   #1
 
Join Date: Sep 2006
Posts: 484
Trader Feedback: 0
Exclamation Directory Checking Code

I want code that checks for a dir. then apply a functions due to the availability of that dir.
How about somethin like this:
Code:
if dir {
(dirc name) then
(function)
    }else{
(function)
}
see I am not sure about the:
Code:
if dir {
If somebody could give me code to replace that part...
THX in advancs
__________________
Need a GFX Guy for EBOOT ICONS, BACkGROUNDS?? I can help you there.
Just see some of my work. PM me for GFX.

Last edited by pspfreak9; 11-25-2006 at 09:33 AM..
pspfreak9 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 09:26 AM   #2
likes kittens....awww....
 
Join Date: Sep 2006
Real First Name: Erik
Location: Detroit
Just Played: Call of Duty:World at War
Posts: 628
Trader Feedback: 0
Default

http://man.he.net/man3/getcwd
-= Double Post =-
also, http://www.informit.com/guides/conte...eqNum=245&rl=1
-= Double Post =-
GOOGLE is your one and only friend.

Last edited by psphacker12.; 11-25-2006 at 09:26 AM.. Reason: Automerged Doublepost
psphacker12. is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 09:29 AM   #3

Developer
 
Join Date: Mar 2006
Posts: 1,026
Trader Feedback: 0
Default

Quote:
Originally Posted by pspfreak9
What a code that checks for a dir. then apply a functions due to the availability of that dir.
What?
__________________

Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197

Quote:
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
Insert_Witty_Name is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 09:34 AM   #4
 
Join Date: Sep 2006
Posts: 484
Trader Feedback: 0
Default

read the code I put it does a better job of explaining than I do
-= Double Post =-
I changed it
__________________
Need a GFX Guy for EBOOT ICONS, BACkGROUNDS?? I can help you there.
Just see some of my work. PM me for GFX.

Last edited by pspfreak9; 11-25-2006 at 09:34 AM.. Reason: Automerged Doublepost
pspfreak9 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 09:45 AM   #5
likes kittens....awww....
 
Join Date: Sep 2006
Real First Name: Erik
Location: Detroit
Just Played: Call of Duty:World at War
Posts: 628
Trader Feedback: 0
Default

I found this
Code:
#include <errno.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
 DIR *pdir;
 struct dirent *pent;

 pdir=opendir("."); //"." refers to the current dir
 if (!pdir){
 printf ("opendir() failure; terminating");
 exit(1);
 }
 errno=0;
 while ((pent=readdir(pdir))){
  printf("%s", pent->d_name);
 }
 if (errno){
 printf ("readdir() failure; terminating");
 exit(1);
 }
 closedir(pdir);
}
GOOOOOGLE POWAH
psphacker12. is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 09:56 AM   #6
 
Join Date: Sep 2006
Posts: 484
Trader Feedback: 0
Default

But how do I put that In the IF function
Cuase I dont want to open the dic If it finds the dirc then it does the function
It is to make sure my app has all nessecry files when some one runs
__________________
Need a GFX Guy for EBOOT ICONS, BACkGROUNDS?? I can help you there.
Just see some of my work. PM me for GFX.
pspfreak9 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 10:04 AM   #7

Developer
 
Join Date: Mar 2006
Posts: 1,026
Trader Feedback: 0
Default

Just use the functions to open directories/files and check the return values from them.

Use opendir for directories and fopen for files.

Code:
pdir=opendir("thedir");
 if(pdir == NULL)
 printf ("Directory doesn't exist...");
Code:
FILE *fp = fopen("somefile.txt", "r");
if(fp == NULL)
printf("File doesn't exist...");
__________________

Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197

Quote:
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
Insert_Witty_Name is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 10:08 AM   #8

Developer
 
tommydanger's Avatar
 
Join Date: Mar 2006
Posts: 166
Trader Feedback: 0
Default

In English please?!

You open the dir to check if if the return value is 0 then it's not there.
Then you know wether it's there or not, then you can do with the dir whatever you want
tommydanger is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 11:36 AM   #9
 
Join Date: Sep 2006
Posts: 484
Trader Feedback: 0
Default

But what if pdir is true (there) how do i make a IF function from that??
-= Double Post =-
How would you put that in code
-= Double Post =-
Can someone help me please
-= Double Post =-
Come on
__________________
Need a GFX Guy for EBOOT ICONS, BACkGROUNDS?? I can help you there.
Just see some of my work. PM me for GFX.

Last edited by pspfreak9; 11-25-2006 at 11:36 AM.. Reason: Automerged Doublepost
pspfreak9 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 12:13 PM   #10
likes kittens....awww....
 
Join Date: Sep 2006
Real First Name: Erik
Location: Detroit
Just Played: Call of Duty:World at War
Posts: 628
Trader Feedback: 0
Default

Ooh, if statements are SOOOO complicated.^^
Code:
if(pdir != NULL)
{
    function1();
}
psphacker12. is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 12:17 PM   #11
 
Join Date: Sep 2006
Posts: 484
Trader Feedback: 0
Default

no no no

your code is if it is == to NULL
But what if it checks for the dirc then if it finds the dirc (the dirc is on the MS) then it does a function. what you are doing is when the dirc isnt there
__________________
Need a GFX Guy for EBOOT ICONS, BACkGROUNDS?? I can help you there.
Just see some of my work. PM me for GFX.
pspfreak9 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 12:19 PM   #12
likes kittens....awww....
 
Join Date: Sep 2006
Real First Name: Erik
Location: Detroit
Just Played: Call of Duty:World at War
Posts: 628
Trader Feedback: 0
Default

Code:
if(pdir != NULL)
{
    function1();
}
-= Double Post =-
== true
!= false

Last edited by psphacker12.; 11-25-2006 at 12:19 PM.. Reason: Automerged Doublepost
psphacker12. is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 12:23 PM   #13
 
Join Date: Sep 2006
Posts: 484
Trader Feedback: 0
Default

again that is false:
Quote:
!= false
-= Double Post =-
NeverMind
-= Double Post =-
Thanks
__________________
Need a GFX Guy for EBOOT ICONS, BACkGROUNDS?? I can help you there.
Just see some of my work. PM me for GFX.

Last edited by pspfreak9; 11-25-2006 at 12:23 PM.. Reason: Automerged Doublepost
pspfreak9 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-25-2006, 12:54 PM   #14

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

psphacker12: That is incorrect:
== means "is equal to"
!= means "is not equal to"

Taking the previous code:
Code:
FILE *fp = fopen("somefile.txt", "r");
if(fp == NULL)
{
    printf("File doesn't exist...");
}
else
{
    // Put code here is the file does exist
}
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
checking , code , directory

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 09:03 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us