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 PostHello,
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 …
Jump to PostIf you are reading a file with the \'s in them, you have no problem. Same with typing the \ from the keyboard at one of your program's prompts. It's only when using the \ in a string in your source code that the double \ is needed.
And …
Jump to PostIs
strcpy(windows,"dir :\/s/b/a-d> .txt");
part of your C++ source code? What have we said about \ in C++ source code? \\ in C++ Source code is a single character -- a single \.
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");
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.