Jump to content
php.lv forumi

sapinos C


ieleja

Recommended Posts

Windows 7-64, Code::Blocks 10.05
atrodot failus ar _findfirst, _findnext, tos neizdodas izdzēst, tiešā veidā (3 priekšpēdējās rindas) failus izdzēš

kods:

#include <fstream>
#include <iostream>
#include <string>

#include <dirent.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(void)
{
    struct _finddata_t dirFile;
    long hFile;

    char cCurrentPath[FILENAME_MAX];
    _getcwd(cCurrentPath, sizeof(cCurrentPath));
    printf ("The current working directory is %s\n", cCurrentPath);

    if ((hFile = _findfirst("*.txt", &dirFile)) != -1)
    {
        do
        {
            if (remove("dirFile.name") != 0)
                {
                    perror("Error deleting file");
                    printf("%s\n", dirFile.name);
                }
                else
                {
                    printf("%s - DEL\n", dirFile.name);
                }
        }
        while (_findnext(hFile, &dirFile) == 0);

        _findclose(hFile);
    }

    remove("abc.txt");
    remove("def.txt");
    remove("ghi.txt");

    return(0);
}

failu struktūra:

dir c:\files

Directory of c:\files

2013.10.12.  00:48    <DIR>          .
2013.10.12.  00:48    <DIR>          ..
2013.10.12.  00:39                 0 abc.txt
2013.10.12.  00:40                 0 def.txt
2013.10.12.  00:46           478,208 delFiles.exe
2013.10.12.  00:40                 0 ghi.txt
               4 File(s)        478,208 bytes

komandas izvads:

C:\files>delFiles.exe
The current working directory is C:\files
Error deleting file: No such file or directory
abc.txt
Error deleting file: No such file or directory
def.txt
Error deleting file: No such file or directory
ghi.txt
Edited by ieleja
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...