Go Back   AnandTech Forums > Software > Programming

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2013
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 03-04-2008, 12:57 PM   #1
scootermaster
Platinum Member
 
Join Date: Nov 2005
Posts: 2,345
Default C++ file manipulation library?

I'm using straight Linux g++ (version 3.something, I believe) and I just need a simple file handling library. For example, if on the command-line, someone enters in ../my/dir/foo.txt I want to be able to strip the directory part and the file name part. That's actually the biggest thing, but anything else that will help with handling files would be cool.

The reason is I have this project that takes input files, and I put them in a centralized directory for cleanlieness. But then I write about 3 files based in the input filename. So based on foo.txt, I write foo.1.csv and foo.1.dot or whatever, but if I just use the filename and append, you can see how they get written to the old directory. Again, for cleanliness, it would be nice to stick them in their own dirs.


Help?
__________________
UNBAN SCHIZOID!
scootermaster is offline   Reply With Quote
Old 03-04-2008, 01:45 PM   #2
Crusty
Lifer
 
Crusty's Avatar
 
Join Date: Sep 2001
Location: ATX
Posts: 12,305
Default C++ file manipulation library?

Just find the location of the last / in the filepath, and do a substring from there to the end.
__________________
Consequences will never be the same!

/^1?$|^(11+?)\1+$/
Crusty is offline   Reply With Quote
Old 03-04-2008, 01:55 PM   #3
Markbnj
Moderator
Programming
 
Markbnj's Avatar
 
Join Date: Sep 2005
Posts: 11,736
Default C++ file manipulation library?

The C++ Boost libraries have a lot of that kind of utility code in them. Although I am not very familiar with them, it looks like this might be of interest:

http://www.boost.org/libs/filesystem/doc/index.htm
__________________
Everytime I try to tell you, the words just come out wrong

**
Some meaningless scribbling of no account

The 4th Realm

Arts and Letters Daily - Get some culture
Markbnj is online now   Reply With Quote
Old 03-04-2008, 04:01 PM   #4
scootermaster
Platinum Member
 
Join Date: Nov 2005
Posts: 2,345
Default C++ file manipulation library?

Quote:
Originally posted by: Markbnj
The C++ Boost libraries have a lot of that kind of utility code in them. Although I am not very familiar with them, it looks like this might be of interest:

http://www.boost.org/libs/filesystem/doc/index.htm
Weird. I thought I checked boost. I'm going to be using their graph library.

But this seems like it might very well do it.

Thanks so much!
__________________
UNBAN SCHIZOID!
scootermaster is offline   Reply With Quote
Old 03-04-2008, 08:41 PM   #5
blackllotus
Golden Member
 
Join Date: May 2005
Posts: 1,875
Default C++ file manipulation library?

Look at the recls library

EDIT: (Its not in boost)
blackllotus is offline   Reply With Quote
Old 03-06-2008, 11:52 AM   #6
programmer
Senior Member
 
Join Date: Mar 2003
Posts: 412
Default C++ file manipulation library?

strrchr is your friend ... maybe you could do something like this without a third-party lib


#include <string.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
char* path = 0;
char* filename = 0;

if (argv[1])
{
path = argv[1]; // just for clarity

filename = strrchr(path, '/');
if (filename) {

*filename++ = 0;

// this will null terminate path and then
// move the filename pointer to the first
// char of the filename... which could be
// a null terminator!

if (*filename == '\0')
filename = 0;
}

printf("The path is %s\n", path ? path : "null");
printf("The filename is %s\n", filename ? filename : "null");
}

return 0;
}



programmer is offline   Reply With Quote
Reply

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

Forum Jump


All times are GMT -5. The time now is 12:36 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.