Jump to content

help to read file name

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
12 replies to this topic

#1
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
I want to read a file name so that I can open and edit it.In terbo C, i was using findfirst and findnext.But with DEV C++ these function are not helping me.Is there any other function to get filename in DEV c++(C langauge function).

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Moved to the correct forum. Are you looking to read the filenames in a particular directory?

#3
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
yes
files are going to be in perticular fixed location

#4
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
I do not understand your problem.. Do you need the path to your file?

Posted via CodeCall Mobile

#5
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
Suppose there are 10 ".txt" files in folder c:\trial.
I need to rename these files, new name is inside that file.
Now to open these files using file function fopen, I need program to read filename first so that I can look into file further for new name.

In terbo C ,function findfirst was giving me file name in structure variable ffblk.name.see below command
"done = _dos_findfirst("C:/trial/*.*",_A_NORMAL,&ffblk);"
Now I suppose to use dev C++, and for same function it is giving error.
Is there any other way to read file name.

I WANT TO AVOID MANUAL ENTRY FOR OLD AND NEW FILE NAME

#6
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
So you want a search function. I see. Are you under windows?

Posted via CodeCall Mobile

#7
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
yes

#8
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
Check out the FindFirstFile() and FindNextFile() (and FindClose()) API functions. Here is an example (although using C++). I'll try to find one using C as well, if you need it. Windows SDK File System: How to search for files in a directory and subdirectories? - CodeGuru Forums
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#9
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
Some resources:

MSDN documentation:
FindNextFile Function (Windows)
FindClose Function (Windows)
FindFirstFile Function (Windows)
FindFirstFileEx Function (Windows)
GetFileAttributes Function (Windows)
SetFileAttributes Function (Windows)

Example from MSDN:
Listing the Files in a Directory (Windows)

A tutorial in C:
adrianxw.dk FindFirstFile 1
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#10
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
Thanks marwex
i try and let you know

#11
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
No problem, dude. Good luck :)
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#12
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
Thank you Marwex that worked
these links will help me in future also