| View previous topic :: View next topic |
| Author |
Message |
ScStyLe How do I cheat?
Reputation: 0
Joined: 07 May 2010 Posts: 6
|
Posted: Mon Nov 01, 2010 12:03 pm Post subject: File directory |
|
|
example:"C:/program files/aaa/abc/axd.txt"
i want this directory but only this "abc/axd.txt" part how can i do this?
please help
VB.net
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Nov 01, 2010 12:11 pm Post subject: |
|
|
it would help if we knew where the program was running from. Is it running from directory ../abc or from ../aaa
_________________
|
|
| Back to top |
|
 |
ScStyLe How do I cheat?
Reputation: 0
Joined: 07 May 2010 Posts: 6
|
Posted: Mon Nov 01, 2010 12:54 pm Post subject: |
|
|
| but i want do this with open file dialog
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Mon Nov 01, 2010 2:53 pm Post subject: |
|
|
In C#
| Code: |
string myStr = "c:\mydir\abc\abc.txt";
string[] arrStr = new string[4];
char[] sep = {'\'};
arrStr = myStr.Split(sep);
for(int x = 0; x < arrStr.Length; x++ )
{
if( x == arrStr.Length - 1 || x == arrStr.Length )
Response.Write(arrStr[x].ToString());
}
|
Will loop through and return the last 2 elements of your array. Not the most elegant solution.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
Deltron Z Expert Cheater
Reputation: 1
Joined: 14 Jun 2009 Posts: 164
|
Posted: Mon Nov 01, 2010 6:09 pm Post subject: |
|
|
A shorter solution would be:
string Str = "a/b/c/d.txt";
int Index = Str.LastIndexOf('/') + 1;
Console.WriteLine(Str.Substring(Index, Str.Length - Index));
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Nov 02, 2010 12:45 pm Post subject: |
|
|
| Deltron Z wrote: | | A shorter solution would be: | This doesn't return "abc/axd.txt", does it?
Since no one is using the requested language, I'll post mine too! C++ with MOC magic: | Code: | QFileInfo f("C:/program files/aaa/abc/axd.txt");
QString s = f.absoluteDir().dirName() + '/' + f.fileName();
// s is now "abc/axd.txt" | Or, if you want to handle it as a string: | Code: | QString s("C:/program files/aaa/abc/axd.txt");
s.remove(QRegExp(".*/(?=.*/)"));
// s is now "abc/axd.txt" | Inverse QString::section() would be cool, but too bad there isn't one.
|
|
| Back to top |
|
 |
ScStyLe How do I cheat?
Reputation: 0
Joined: 07 May 2010 Posts: 6
|
Posted: Tue Nov 02, 2010 2:36 pm Post subject: |
|
|
| but i need do this with vb.net
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Tue Nov 02, 2010 3:20 pm Post subject: |
|
|
Couldn't tell you how in VB, I've always hated that language. You could still do it in either C# or C++ using MS Visual C# or MS Visual C++ and still make use of the .NET roll up.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
|