I am trying to grab the raw filename without the extension from the filename passed in arguments:
int main ( int argc, char *argv[] ) { // Check to make sure there is a single argument if ( argc != 2 ) { cout<<"usage: "<< argv[0] <<" <filename>\n"; return 1; } // Remove the extension if it was supplied from argv[1] -- pseudocode char* filename = removeExtension(argv[1]); cout << filename; }
The filename should for example be "test" when I passed in "test.dat".
bat Now right click any file you want to disassociate and choose 'Open with' - 'Choose another app' -' More Apps' Check the box marked 'Always use this app' Scroll to the bottom and click 'Look for another app on this PC' Navigate to the XXX. bat on your Desktop and select that Finally delete XXX.
Open File Explorer and click View tab, Options. In Folder Options dialog, move to View tab, untick Hide extensions for known file types option, OK. Then you will se file's extension after its name, remove it.
The function splitext() in os. path allows you to separate the root and extension of a specified file path. A tuple made up of the root string and the extension string is the function's output.
size_t lastindex = fullname.find_last_of("."); string rawname = fullname.substr(0, lastindex);
Beware of the case when there is no "." and it returns npos
This works:
std::string remove_extension(const std::string& filename) { size_t lastdot = filename.find_last_of("."); if (lastdot == std::string::npos) return filename; return filename.substr(0, lastdot); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With