Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

struct dirent not reading proper file name

Posted on 2004-09-05
9
338 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 125 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 125 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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 125 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 125 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

789 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