当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Stats.isDirectory方法代码示例

本文整理汇总了TypeScript中fs.Stats.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Stats.isDirectory方法的具体用法?TypeScript Stats.isDirectory怎么用?TypeScript Stats.isDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fs.Stats的用法示例。


在下文中一共展示了Stats.isDirectory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: walk

export function walk(path: string, options: WalkOptions) {
	let stats: Stats
	try {
		stats = (options.follow !== false ? statSync : lstatSync)(path)
	} catch (e) {
		options.error && options.error(e, path)
		return
	}
	if (stats.isFile()) {
		options.file && options.file(path, stats)
	} else if (stats.isDirectory()) {
		if (!options.dir || options.dir(path, stats) !== false) {
			let entries: string[]
			try {
				entries = readdirSync(path)
			} catch (e) {
				options.error && options.error(e, path)
				return
			}
			if (!options.walkDir || options.walkDir(path, entries, stats) !== false) {
				for (const entry of entries) {
					walk(join(path, entry), options)
				}
			}
		}
	} else {
		options.other && options.other(path, stats)
	}
}
开发者ID:tpack,项目名称:utilskit,代码行数:29,代码来源:fs.ts

示例2:

export const getFileType = (stats: Stats): FileType => {
    return stats.isSymbolicLink() ? FileType.SymbolicLink :
        stats.isFile() ? FileType.File :
            stats.isDirectory() ? FileType.Directory :
                stats.isBlockDevice() ? FileType.BlockDevice :
                    stats.isCharacterDevice() ? FileType.CharacterDevice :
                        stats.isFIFO() ? FileType.FIFO :
                            stats.isSocket() ? FileType.Socket :
                                FileType.Other;
};
开发者ID:Kuchasz,项目名称:smart-downloader,代码行数:10,代码来源:FileTypeAccessor.ts

示例3: findFile

function findFile(dir: string, fileName: string): string {
	'use strict';
	let children: string[] = fs.readdirSync(dir);
	for (let i: number = 0; i < children.length; ++i) {
		let path: string = dir + '/' + children[i];
		let stat: Stats = fs.statSync(path);
		if (stat.isFile()) {
			if (children[i] === fileName) {
				return path;
			}
		} else if (stat.isDirectory()) {
			let result: string = findFile(path, fileName);
			if (result) {
				return result;
			}
		}
	}
	return undefined;
}
开发者ID:data9824,项目名称:SavannaTalk,代码行数:19,代码来源:main.ts

示例4: get_listing

export async function get_listing(
  path: string,
  hidden: boolean = false
): Promise<ListingEntry[]> {
  const dir = HOME + "/" + path;
  const files: ListingEntry[] = [];
  let name: string;
  for (name of await callback(readdir, dir)) {
    if (!hidden && name[0] === ".") {
      continue;
    }
    let entry: ListingEntry;
    try {
      // I don't actually know if file can fail to be JSON-able with node.js -- is there
      // even a string in Node.js that cannot be dumped to JSON?  With python
      // this definitely was a problem, but I can't find the examples now.  Users
      // sometimes create "insane" file names via bugs in C programs...
      JSON.stringify(name);
      entry = { name };
    } catch (err) {
      entry = { name: "????", error: "Cannot display bad binary filename. " };
    }

    let stats: Stats;
    try {
      stats = await callback(lstat, dir + "/" + entry.name);
      if (stats.isSymbolicLink()) {
        entry.issymlink = true;
        try {
          stats = await callback(stat, dir + "/" + entry.name);
        } catch (err) {
          // broken link -- just report info about the link itself...
        }
      }
      entry.mtime = stats.mtime.valueOf() / 1000;
      if (stats.isDirectory()) {
        entry.isdir = true;
        try {
          const v = await callback(readdir, dir + "/" + entry.name);
          if (hidden) {
            entry.size = v.length;
          } else {
            // only count non-hidden files
            entry.size = 0;
            for (let x of v) {
              if (x[0] != ".") {
                entry.size += 1;
              }
            }
          }
        } catch (err) {
          // just ignore -- no size info.
        }
      } else {
        entry.size = stats.size;
      }
    } catch (err) {
      entry.error = `${entry.error ? entry.error : ""}${err}`;
    }
    files.push(entry);
  }
  return files;
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:63,代码来源:directory-listing.ts


注:本文中的fs.Stats.isDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。