Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# Load Method

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sat Nov 21, 2009 1:34 am    Post subject: C# Load Method Reply with quote

is there a method to load all the files from a folder and then get the names of the files?
like.. setting them in an array

the thing is like this
I have folders like this

Cards/ActionBar
Cards/Characters
and
Cards/ActionBar/equips

I have pictures in that 3 files

I know how to do it the long and inefficient way
like getting all the names of the files inside an array and then just concatenate the files on the load function ... but that will take me some time, so I'm asking for help if maybe anyone haves a method to directly load all the files and then write the names inside of my array for me?


I tried searching and I tried with using this library System.IO and Directory.getFiles(path) so I could make an array but at the moment of calling it

string[] ActionBar = Directory.GetFiles("Cards\\ActionBar\\");

it doesnt want to work.. its giving me "could not find part of the path "
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Nov 21, 2009 3:16 am    Post subject: Reply with quote

the answer is indeed Directory.GetFiles()

one of the overloads lets you specify if you want it to search sub directories as well.

use Directory.GetCurrentDirectory() to help get a meaningful path
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Nov 21, 2009 3:18 am    Post subject: Reply with quote

you also have Directory.GetDirectories to view all the sub folders in your current directory
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sat Nov 21, 2009 12:00 pm    Post subject: Reply with quote

I dont want to get the subfolders since I want to sort them more accurately.

ok ok, thanks I got it now
Code:

string[] ActionBar = Directory.GetFiles(ActionBarpath + "\\Content\\Cards\\ActionBar\\");
        string[] Equips = Directory.GetFiles(ActionBarpath + "\\Content\\Cards\\ActionBar\\Equips");
        string[] CharactersAlliance = Directory.GetFiles(ActionBarpath + "\\Content\\Cards\\Characters\\Alliance\\");
        string[] CharactersHorde = Directory.GetFiles(ActionBarpath + "\\Content\\Cards\\Characters\\Horde\\");
        string[] CharactersMonster = Directory.GetFiles(ActionBarpath + "\\Content\\Cards\\Characters\\Monster\\");


hmm but my array of strings is not getting what I wanted... its getting the full path ... not the names... and I dont know if other will be able to run it if I just fix it with a string.remove(1,x);

-- edit:

k got it with Path.GetFileName but now I need to eliminate the .xnb of the end xP

k done guys, thanks for the help n.n
Code:
void FixNames()
        {
            int x;
            int y;
            y = Equips.Length;
            char[] xnb = { 'b', 'n', 'x', '.' };

            for (x = 1; x < y; x++)
            {
                Equips[x] = Path.GetFileName(Equips[x]);
                Equips[x] = Equips[x].TrimEnd(xnb);
            }
            for (x = 1; x < y; x++)
            {
                ActionBar[x] = Path.GetFileName(ActionBar[x]);
                ActionBar[x] = ActionBar[x].TrimEnd(xnb);
            }
            for (x = 1; x < y; x++)
            {
                CharactersAlliance[x] = Path.GetFileName(CharactersAlliance[x]);
                CharactersAlliance[x] = CharactersAlliance[x].TrimEnd(xnb);
            }
            for (x = 1; x < y; x++)
            {
                CharactersHorde[x] = Path.GetFileName(CharactersHorde[x]);
                CharactersHorde[x] = CharactersHorde[x].TrimEnd(xnb);
            }
            for (x = 1; x < y; x++)
            {
                CharactersMonster[x] = Path.GetFileName(CharactersMonster[x]);
                CharactersMonster[x] = CharactersMonster[x].TrimEnd(xnb);
            }
        }

yeah Idk why I made so many for loops.. it could be all contained in only 1 (( fixing it in my code but not going to post the result xP ))
actually I didn't notice there was a problem xP I wasnt taking in consideration the array[0]
xP
here is it fixed

Code:
void FixNames()
        {
            int x;
            int y;
            y = Equips.Length;
            char[] xnb = { 'b', 'n', 'x', '.' };

            for (x = 0; x < y; x++)
            {
                Equips[x] = Path.GetFileName(Equips[x]);
                Equips[x] = Equips[x].TrimEnd(xnb);
           
                ActionBar[x] = Path.GetFileName(ActionBar[x]);
                ActionBar[x] = ActionBar[x].TrimEnd(xnb);
           
                CharactersAlliance[x] = Path.GetFileName(CharactersAlliance[x]);
                CharactersAlliance[x] = CharactersAlliance[x].TrimEnd(xnb);
           
                CharactersHorde[x] = Path.GetFileName(CharactersHorde[x]);
                CharactersHorde[x] = CharactersHorde[x].TrimEnd(xnb);
           
                CharactersMonster[x] = Path.GetFileName(CharactersMonster[x]);
                CharactersMonster[x] = CharactersMonster[x].TrimEnd(xnb);
            }
        }


(( just noticed one more error in the code...))

____________________

last fix ( hopefully )

Code:
void FixNames()
        {
            int x, y, z, a, h, m;
           
            y = Equips.Length;
            z = ActionBar.Length;
            a = CharactersAlliance.Length;
            h = CharactersHorde.Length;
            m = CharactersMonster.Length;
           
            char[] xnb = { 'b', 'n', 'x', '.' };

            for (x = 1; x < y; x++)
            {
                Equips[x] = Path.GetFileName(Equips[x]);
                Equips[x] = Equips[x].TrimEnd(xnb);
            }
            for (x = 1; x < z; x++)
            {
                ActionBar[x] = Path.GetFileName(ActionBar[x]);
                ActionBar[x] = ActionBar[x].TrimEnd(xnb);
            }
            for (x = 1; x < a; x++)
            {
                CharactersAlliance[x] = Path.GetFileName(CharactersAlliance[x]);
                CharactersAlliance[x] = CharactersAlliance[x].TrimEnd(xnb);
            }
            for (x = 1; x < h; x++)
            {
                CharactersHorde[x] = Path.GetFileName(CharactersHorde[x]);
                CharactersHorde[x] = CharactersHorde[x].TrimEnd(xnb);
            }
            for (x = 1; x < m; x++)
            {
                CharactersMonster[x] = Path.GetFileName(CharactersMonster[x]);
                CharactersMonster[x] = CharactersMonster[x].TrimEnd(xnb);
            }
        }
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites