lukeh53 Posted December 16, 2009 Posted December 16, 2009 Okay, i am making a program and i need to make files in a certain directory, so i figured i would use the mkdir that is already in the command prompt. my problem is that when i pass C: through system() it doesnt change the directory. cd wont do anything either. thanks in advance, -luk53 Quote
requiem Posted January 17, 2010 Posted January 17, 2010 You don't need the system command for that, just use the directory's path. For instance, if you wanted to make a text file on the C: drive you would do something like: fout.open ( "C:\mytext.txt" ) That will make a text file in that path (kinda straight forward :D ) But if you don't want it so exact, use something more like: fout.open ( "..\mytext.txt" ) That will make the file in the directory above where your program is. I hope that's what you needed. Quote
Ogma Posted March 18, 2010 Posted March 18, 2010 When you write file names like C:\Bla\bla.txt C++ sees it as C:Blabla.txt. This is because \ is reserved for escape sequences. So you need to use the escape sequence to make the \. So it should be C:\\Bla\\bla.txt Quote
etftw Posted March 24, 2010 Posted March 24, 2010 (edited) Okay, i am making a program and i need to make files in a certain directory, so i figured i would use the mkdir that is already in the command prompt. my problem is that when i pass C: through system() it doesnt change the directory. cd wont do anything either. thanks in advance, -luk53 There is no need to use the cd command, you can pass an absolute path to the command which will indicate exactly where it should be creating the new folder, like this: system("mkdir C:\\parent_folder\\new_folder"); You should probably try out requiem's method however, as if I am correct the method he has showed you will automatically create the directory if it doesn't exist when the file is created :) A lot less messy then messing around with system commands. Edited March 24, 2010 by etftw Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.