|
If you are looking to roll your own solution, when you encounter a * in the pattern, iterate through each successive character in the string-to-match until the character following the * is encountered. For example:
char *pszPattern = "comp_*_sales_*_?pav";
// if x points here ^
char *pszString = "comp_toyota_sales_inhouse_mpav";
// and y points here ^
// advance x one character to the _, and advance y until that character is encountered
When you encounter a ? in the pattern, iterate through one character in the string-to-match. As long as the next character matches the character following the ?, it matches.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Not sure why no-one else has mentioned it yet, but have you looked into the PathMatchSpec(...) function? It sounds like exactly the kind of functionality you are looking for, which is MS-DOS-style wildcard matching...
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hi there,
I am trying to use CreateFile to open up a file handle however in some instances it doesnt work. Is there a way to convert a file location string into its exact case-sensitive string?
For example.
lszLogFile = "C:\\TeSt\\TeSt.txt";
HANDLE hLogFile = NULL;
hLogFile = CreateFile(lszLogFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
lszLogFile is the actual parameter that works with create file and a handle is created, however if
lszLogFile = "C:\\test\\test.txt";
Then a handle will not be created. Is there a way to find out what the actual Directory string is?
Thanks guys,
Robbie
-- modified at 13:10 Monday 19th June, 2006
Added the extra backslashes, and no that wasnt the problem.
|
|
|
|
|
Sure your problem is case related, not a lack of \ characters?
Steve S
Developer for hire
|
|
|
|
|
capricious_001 wrote: lszLogFile = "C:\\test\test.txt";
Should be:
lszLogFile = "C:\\test<font size=6>\\</font>test.txt";
Maxwell Chen
|
|
|
|
|
|
The gap is too large!
Maxwell Chen
|
|
|
|
|
|
I'm confused too ...
Maxwell Chen
|
|
|
|
|
toxcct wrote: i can't see any difference
Because the OP has been modified.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: toxcct wrote:
i can't see any difference
Because the OP has been modified.
nope David, because i was joking...
check the joke icon ;)
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
capricious_001 wrote: lszLogFile = "C:\\TeSt\TeSt.txt";
This should be:
lszLogFile = "C:\\TeSt\\TeSt.txt";
capricious_001 wrote: Then a handle will not be created.
Why not? Have you checked the return value of GetLastError() ?
capricious_001 wrote: Is there a way to find out what the actual Directory string is?
It's whatever value you have assigned to lszLogFile .
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
lol nono, the path directory is correct. I just forgot the extra backslash in this example.
I tested it. having lszLogFile = "C:\\TeSt\\TeSt.txt"; works rather than having all the characters as lower case. So really the question is how do i retreive the case sensitive file path of that file
-- modified at 13:09 Monday 19th June, 2006
I wrote that piece of code in my original post on the fly. I hate copying and pasting my code because its just too much too read.
|
|
|
|
|
capricious_001 wrote: I hate copying and pasting my code because its just too much too read.
But copy/paste is the preferred method as needless posts can be avoided. You only need to paste the relevant snippets, not an entire program.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
capricious_001 wrote: lszLogFile = "C:\\test\\test.txt";
OK. I've read your modified post.
Now it looks like a "chicken-and-egg" question though.
capricious_001 wrote: Then a handle will not be created. Is there a way to find out what the actual Directory string is?
To retrieve the so-called *exact* file path, you need a valid file handle and pass the valid handle into some API.
To get a file handle without knowing the *exact* case-sensitive path (in your case), you can only input the path in case-insensitive form which results in failure (in your case).
Anyway, my system works very well with both your code snippets. :->
Maxwell Chen
|
|
|
|
|
I used GetLastError() and figured out that it was an issue with my type-casting, but I fixed it lol. Thanks for the help.
|
|
|
|
|
Windows file systems are not case-sensitive. If C:\test\test.txt is failing, it's due to something else, not the case of the letters. Check the value of GetLastError()
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
hi everybody,
i am bake bihari from bihar .i have one problem that ,i am write different size of string in file but at reading time i don't know size of string which i have to read
,at time i want to read only one string
|
|
|
|
|
you could write and heading integer before each string so that you read it first, and so, can deduce the length of your string...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
How are you writing said string to file?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
One solution can be that every time you insert a new string into file, you insert it in a new line. Now you can get every string using getline(...) function. How's that?
Good luck
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
One Classical way of doing this is to read the string twice! First time you read it, just read it into a buffer of one char, and count the chars.(I assume you want to read a zero terminated string.) In that case, you know you reached the End of the string when you read a 0. At that stage, you have a Character count, which is the size of the string you want to read. Now you can allocate an ample buffer, and read the lot. Simple enough? Yes but No.
Unfortunately, for reasons long since lost in the mist of history, not all characters always consume one byte. Our friends in Japan and China may have a word or two to say about that, but, atleast in their case it is usefull to their language. In the western case, it is a Hangover from the past. The long and short of it is, that the End of a Line in a Text file is recorded as a \r\n two byte sequence. (This is how it is recorded on your Disk).
When you read it back from your disk into a Buffer, the \r is stripped from the file, and all you will find in your buffer is a single \n.
This has important consequences, the main one being that the offset of a character in the buffer is potentially different to the offset of the same position in the File.
There is a way around all this, the translation mechanism depends on how you open the underlaying file.
If you open a file as fopen("File","r") or fopen("File","w")the Library will insert, or delete the \r bytes when reading or writing between buffer and file.
If you open a file as fopen("File","rb") or fopen("File","wb")the Library read or write between buffer and file without translation.
All tends to work well, if you read a file in the same mode it was written by, and if you do not do daft things, such as trying to count chars in a file. Armed with the above knowledge, I suggest you get creative, and do the needed
LateNightsInNewry
|
|
|
|
|
Hey guys,
I am receiving this error in VC++
testing_project.obj : error LNK2001: unresolved external symbol "bool __cdecl GetRSLocation_Reg(char *)" (?GetRSLocation_Reg@@YA_NPAD@Z)
C:\testing_project.exe : fatal error LNK1120: 1 unresolved externals
</pre
Where <code>char *</code> is a typedef for <code>LPSTR</code>
These are the libraries I have included in my project:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Here are my project options
<pre>
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/testing_project.pdb" /debug /machine:I386 /out:"C:\testing_project.exe" /pdbtype:sept
Anyone know what the problem could be?
Thanks in advance!
Robbie
|
|
|
|
|
I fixed it! In my function definition parameters, I was passing a value by reference but in my function prototype I wasnt. Sorry my bad lol.
|
|
|
|
|
Whenever I do:
CString userInput;
CString device,
cmd,
input1,
input2;
int i;
i = _stscanf(userInput,_T("%s %s %s %s"), &device, &cmd, &input1, &input2);
I get this warning:
c:\...cpp(72) : warning C4996: 'swscanf' was declared deprecated
c:\program files\microsoft visual studio 8\vc\include\wchar.h(809) : see declaration of 'swscanf'
Message: 'This function or variable may be unsafe. Consider using swscanf_s instead.
So, I run my application everything prints ok. Then when I goto close my application I get:
"An unhandled win32 exception occurred in LEDs_try2.exe [2860]."
I then click to debug then I get:
Unhandled exception at 0x783252f8 (mfc80ud.dll) in LEDs_try2.exe: 0xC0000005: Access violation writing location 0x0035002e.
-AND-
MS Visual Studio opens up the file: atlsimpstr.h
Points to line 109 which is:
"if( _AtlInterlockedDecrement( &nRefs ) <= 0 )"
Would please someone explain to me what I'm doing wrong?
Thanks.
Kitty5
|
|
|
|