Hello,
I am making some program, and have some problem, i want to list all files that are on HD, and if I want to list all files in C: with this command with only one backslash after C:( system(dir C:\ /s/b/a-d> C.txt)) it only list files that are in C:\Users\Tomo\Documents\Visual Studio 2008\Projects\name\name, but when I enter this command with two backslashs after C:(system(dir C:\\ /s/b/a-d> C.txt)) it lists all files in C:, what is OK, but there are many files that I want to read, and I cant add everytime one backslash more,(if I want to list all files in D:, I can do it with two or one backslash, no difference).
Note: I can list all files whith one backslash in CMD, but not in c++.
Hope you understand my problem.
Thans.
lima01 0 Newbie Poster
Recommended Answers
Jump to PostAnytime you want a special character in a string, you use \x where x is the character. Therefore, the \ itself is a special character, too. So you must use \x format to add one -- hence \\
Jump to PostIf you want a list of all the files on your he you don't need the \ character at all. Just this:
system("dir c: /s > c.txt");
Jump to PostYes you do. The command above will list files starting with the current directory -- probably from the location of the .exe file.
system("dir c:\\ /s > c.txt");
will start listing from the root directory.You are right -- I thought it worked, but all it gave me was a …
Jump to PostOk guys, I understand that I need to use double \\, but for example, if I have an txt file - 1.txt, in wich is "C:\Users\2.txt", and if I read that(C:\Users\2.txt) and save it to -string[20]={C:\Users\2.txt}, how could I open that file using identifier string(not C:\Users\2.txt)?
PS. I dont know …
Jump to Post>>ompare every character with \ and then add another one but it would be too slow,
HOW MANY TIMES DO WE HAVE TO TELL YOU WHAT YOU DO NOT HAVE TO DO THAT!!! :@
All 17 Replies
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
dusktreader 137 Posting Whiz in Training
lima01 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
lima01 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
lima01 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
dusktreader 137 Posting Whiz in Training
lima01 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
lima01 0 Newbie Poster
lima01 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.