Solved

struct dirent not reading proper file name

Posted on 2004-09-05
9
335 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I test for current date? 9 102
using pointers to pointers to write to a two dimensional array 16 91
Super Scope, DHCP 5 77
Why is compiler in oracle server ? 9 65
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.

770 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