mirror of
https://github.com/depp/syncfiles.git
synced 2025-01-24 03:37:01 +00:00
List files in directory from sync tool
GitOrigin-RevId: 738baa6a94ac864f121167798e4ea93f95d1c420
This commit is contained in:
parent
fa2f0d12a0
commit
bd293bb3dd
51
sync.c
51
sync.c
@ -17,49 +17,50 @@ static int c2pstr(Str255 ostr, const char *istr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int list_dir(const char *dirpath) {
|
static int list_dir(const char *dirpath) {
|
||||||
unsigned char path[257];
|
Str255 ppath;
|
||||||
WDPBRec wd;
|
|
||||||
CInfoPBRec ci;
|
CInfoPBRec ci;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
int i, result = 0;
|
short vRefNum;
|
||||||
|
long dirID;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (c2pstr(path, dirpath)) {
|
if (c2pstr(ppath, dirpath)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
memset(&wd, 0, sizeof(wd));
|
memset(&ci, 0, sizeof(ci));
|
||||||
wd.ioNamePtr = path;
|
ci.dirInfo.ioNamePtr = ppath;
|
||||||
err = PBOpenWDSync(&wd);
|
err = PBGetCatInfoSync(&ci);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
fprintf(stderr, "## Error: could not open directory '%s' (err = %d)\n", dirpath, err);
|
fprintf(stderr, "## Error: PBGetCatInfoSync: %d\n", err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
vRefNum = ci.dirInfo.ioVRefNum;
|
||||||
|
dirID = ci.dirInfo.ioDrDirID;
|
||||||
|
printf("vRefNum: %d; dirID: %d\n", vRefNum, dirID);
|
||||||
|
if ((ci.dirInfo.ioFlAttrib & kioFlAttribDirMask) == 0) {
|
||||||
|
fprintf(stderr, "## Error: not a directory: %s\n", dirpath);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("Path: %s\n", dirpath);
|
|
||||||
printf(" VREF: %d\n", wd.ioVRefNum);
|
|
||||||
|
|
||||||
for (i = 1; i < 10; i++) {
|
for (i = 1; i < 100; i++) {
|
||||||
memset(&ci, 0, sizeof(ci));
|
memset(&ci, 0, sizeof(ci));
|
||||||
ci.dirInfo.ioNamePtr = path;
|
ci.dirInfo.ioNamePtr = ppath;
|
||||||
ci.dirInfo.ioVRefNum = wd.ioVRefNum;
|
ci.dirInfo.ioVRefNum = vRefNum;
|
||||||
|
ci.dirInfo.ioDrDirID = dirID;
|
||||||
ci.dirInfo.ioFDirIndex = i;
|
ci.dirInfo.ioFDirIndex = i;
|
||||||
err = PBGetCatInfoSync(&ci);
|
err = PBGetCatInfoSync(&ci);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
printf(" err\n");
|
if (err == fnfErr) {
|
||||||
if (err != fnfErr) {
|
break;
|
||||||
result = 1;
|
|
||||||
fprintf(stderr, "## Error: could not list directory '%s' (err = %d)\n", dirpath, err);
|
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "## Error: could not list directory '%s' (err = %d)\n", dirpath, err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
path[path[0] + 1] = '\0';
|
ppath[ppath[0] + 1] = '\0';
|
||||||
printf(" File: '%s'\n", path + 1);
|
printf(" File: '%s'\n", ppath + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PBCloseWDSync(&wd);
|
return 0;
|
||||||
if (err != 0) {
|
|
||||||
fprintf(stderr, "## Error: could not close directory '%s' (err = %d)\n", dirpath, err);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp) {
|
int main(int argc, char **argv, char **envp) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user