Functions for working with paths.
More...
#include "tpcclibConfig.h"
#include "tpcextensions.h"
#include "tpcfileutil.h"
Go to the source code of this file.
Functions for working with paths.
Definition in file pathexist.c.
◆ pathCreate()
| int pathCreate |
( |
const char * | pathname | ) |
|
Create path.
- See also
- pathExist, pathRemove, pathFileNr, filenameRmFile
- Returns
- Returns 0, if path could be created or exists already, 1, if it does not exist and cannot be created.
- Parameters
-
| pathname | Name of path to create; can contain subdirectories. |
Definition at line 81 of file pathexist.c.
84 {
85
86 if(pathname==NULL ||
strnlen(pathname, 2)<1)
return(1);
89
90 char *lpath=
strdup(pathname);
91 char *cptr=strrchr(lpath, '/'); if(cptr==NULL) cptr=strrchr(lpath, '\\');
92 if(cptr!=NULL) {
93 *cptr=(char)0;
95 if(ret!=0) {free(lpath); return(1);}
96 }
97 free(lpath);
98
99#ifndef HAVE__MKDIR
100
101 if(mkdir(pathname, 0777)!=0 && errno!=EEXIST) return(1); else return(0);
102#else
103
104 if(_mkdir(pathname)!=0 && errno!=EEXIST) return(1); else return(0);
105#endif
106}
int fileExist(const char *filename)
int pathExist(const char *pathname)
int pathCreate(const char *pathname)
char * strdup(const char *s)
size_t strnlen(const char *s, size_t n)
Referenced by imgWriteDICOM(), imgWriteNifti(), and pathCreate().
◆ pathExist()
| int pathExist |
( |
const char * | pathname | ) |
|
Check if specified directory (path) exists.
- See also
- fileExist, pathFileNr, filenameRmFile
- Returns
- Returns 1, if path exists, and 0 if it does not or is not a directory.
- Parameters
-
| pathname | Name of path to check. |
Definition at line 17 of file pathexist.c.
20 {
21 if(pathname==NULL) return(0);
22 int len=strlen(pathname);
23 if(len<1) return(0);
24 char *str=
strdup(pathname);
25 if(len>1 && str[len-1]=='/') {
26 if(len<2) {free(str); return(0);}
27 str[len-1]='\0';
28 }
29 struct stat fst;
30 if(stat(str, &fst)!=0) {free(str); return(0);}
31 free(str);
32 if(S_ISDIR(fst.st_mode)) return(1);
33 return(0);
34}
Referenced by dcmFileList(), imgFormatFromFName(), imgRead(), imgWriteDICOM(), pathCreate(), pathFileList(), pathFileNr(), pathRemove(), and pathRemoveFiles().
◆ pathRemove()
| int pathRemove |
( |
const char * | pathname | ) |
|
Remove path.
- See also
- fileExist, pathFileNr, filenameRmFile
- Returns
- Returns 0, if path could be removed or it did not exist, 1, if it exists and cannot be removed.
- Parameters
-
| pathname | Name of path to remove. |
Definition at line 43 of file pathexist.c.
46 {
49 if(rmdir(pathname)==0) return(0); else return(1);
50}
Referenced by imgWriteDICOM().
◆ pathRemoveFiles()
| int pathRemoveFiles |
( |
const char * | pathname | ) |
|
Remove regular files in specified path. Subfolders are not affected.
- See also
- fileExist, pathFileNr, pathFileList, pathRemove
- Returns
- Returns 0, if files could be removed or did not exist, 1, in case of an error.
- Parameters
-
| pathname | Name of path from where to remove files. |
Definition at line 58 of file pathexist.c.
61 {
66 if(n==0) {
iftFree(&ift);
return(0);}
67 for(
int i=0; i<ift.
keyNr; i++) {
69 }
71 return(0);
72}
unsigned short int pathFileList(const char *pathname, IFT *ift)