Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

struct dirent not reading proper file name

Posted on 2004-09-05
9
Medium Priority
?
349 Views
Last Modified: 2008-02-01

hi..
i am using struct dirent to  search for a given file in a directory.the trouble is that if the name of the file is LP36-3_27FP.phd.1 it is reading it as LP-3~1.1 (and some are taking hexadecimal value) and hence strcmpi is not working.Can anyone help me solve my problem?
0
Comment
Question by:rohin1702
9 Comments
 
LVL 11

Accepted Solution

by:
avizit earned 500 total points
ID: 11984697
are you on WIN/DOS based system ?
if so you may have the DOS filename restrictions of

8 characters and another 3 for extenstion

0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 11984800
Yeah.struct dirent reads in the dos filenames.

What compiler are you on?

You could try system("dir/b >>dir.txt"); if on windows platform.

and read from that text file.One filename on one line.

dir/b gives you the bare filenames without the size etc. details and i redirect the output to a file dir.txt
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 500 total points
ID: 11985371
There's a set of API's for reading the LONG file names.   Basically like the regular file API's,
you just do an int 71h instead of int 21h.  See:

http://www.frontiernet.net/~fys/longfile.htm



0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 11990192
If you are already on a Win32 system, use the native way:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/listing_the_files_in_a_directory.asp ("Listing the Files in a Directory")

#define _WIN32_WINNT 0x0501

#include <windows.h>
#include <string.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
   WIN32_FIND_DATA FindFileData;
   HANDLE hFind = INVALID_HANDLE_VALUE;
   char DirSpec[MAX_PATH];  // directory specification
   DWORD dwError;

   printf ("Target directory is %s.\n", argv[1]);
   strncpy (DirSpec, argv[1], strlen(argv[1])+1);
   strncat (DirSpec, "\\*", 3);

   hFind = FindFirstFile(DirSpec, &FindFileData);

   if (hFind == INVALID_HANDLE_VALUE)
   {
      printf ("Invalid file handle. Error is %u\n", GetLastError());
      return (-1);
   }
   else
   {
      printf ("First file name is %s\n", FindFileData.cFileName);
      while (FindNextFile(hFind, &FindFileData) != 0)
      {
         printf ("Next file name is %s\n", FindFileData.cFileName);
      }
   
      dwError = GetLastError();
      if (dwError == ERROR_NO_MORE_FILES)
      {
         FindClose(hFind);
      }
      else
      {
         printf ("FindNextFile error. Error is %u\n", dwError);
         return (-1);
      }
   }
   return (0);
}
0
 

Author Comment

by:rohin1702
ID: 12100791
i am using turbo C compiler hence system mot working,
can someone suggest a method for lisitng the file name even if without the extension?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 12102606
>>can someone suggest a method for lisitng the file name even if without the extension?

Thanx for coming back so early, that was only two weeks, wow. Why aren't you using the method(s) above? You are using a compiler from stone age, so long filenames will *not* work at all.
0
 
LVL 9

Assisted Solution

by:ankuratvb
ankuratvb earned 500 total points
ID: 12121262
>i am using turbo C compiler hence system mot working,

Thats not true.system() works.It won't in the IDE.but try running your EXE from the command line or use the command line compiler tcc.

It works.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question