| |

VerySource

 Forgot password?
 Register
Search
View: 895|Reply: 6

I would like to ask, how to get a file exists, not using FileExists

[Copy link]

2

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-17 20:30:01
| Show all posts |Read mode
Ask you prawn:
 How to find out if a file exists or not with FileExists, is there any other function?
Reply

Use magic Report

2

Threads

19

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 United States

Post time: 2020-4-22 10:30:01
| Show all posts
// Give you a custom function to get whether the specified file exists
bool FileExist (LPCTSTR szFindPath)
{
int count = 0;
int i = 0;
WIN32_FIND_DATA fd;
HANDLE hFind;
if (strlen ((char *) szFindPath) <= 0)
return false;
char path [257];
    char * pPath;
    pPath = path;
    count = strlen (szFindPath);
if (count <= 0)
return false;
    

// Get the path string from front to back
for (i = 0; i <count; i ++)
{
        if (* (szFindPath + i) == '\\')
break;
* (pPath + i) = * (szFindPath + i);
}

   * (pPath + i) = '\\';
   * (pPath + i + 1) = '\0';
    hFind = FindFirstFile (szFindPath,&fd);

if (hFind! = INVALID_HANDLE_VALUE)
{
FindClose (hFind);
}

return hFind! = INVALID_HANDLE_VALUE;
}
Reply

Use magic Report

0

Threads

25

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-4-23 12:45:01
| Show all posts
(access (filename, F_OK)) == 0)
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-5-12 12:30:01
| Show all posts
Find by example, compare with the desired file name
CFileFind ff;
strPltfind = "*. *";
BOOL res = ff.FindFile (strPltfind);
while (res)
{
res = ff.FindNextFile ();
filename = ff.GetFilePath ();
// ----- Open and store file data ---------------------
// You can store filename
         if (! filename.Compare ("/ * file name to find * /"))
         {
         ..................
         }
}
for reference only:_)
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-13 12:00:01
| Show all posts
CString strTmp = "full file path";
CFileFind FileFind;
BOOL br = FileFind .FindFile (strTmp);
if (br)
{
  //presence
}
else
{
  //does not exist
}
Reply

Use magic Report

0

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Unknown

Post time: 2020-5-13 16:45:01
| Show all posts
That's so troublesome, just use pathfileexists ("c:\\a.txt"); to judge
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-14 11:15:01
| Show all posts
#include <io.h>

...
if (_access ("c:\\path.ext", 0)! = -1)
    // File exists
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list