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


TypeScript fs.readdir函数代码示例

本文整理汇总了TypeScript中fs.readdir函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readdir函数的具体用法?TypeScript readdir怎么用?TypeScript readdir使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: frmdir

// Originally adopted from https://gist.github.com/tkihira/2367067
// Rewritten on 25 April 2016 by Romans Volosatovs

// Recursive rm function
// Calls 'cleandir' with i=0 to empty and
// consequently remove the given 'dir'
function frmdir(dir: string, cb: (err: any) => void): void {
	fs.readdir(dir, (err, files): void => {
		if (err) {
			cb(err);
			return;
		}

		cleandir(dir, files, 0, (err) => {
			if (err) {
				cb(err);
				return;
			}

			fs.rmdir(dir, (err) => {
				if (err) {
					cb(err);
				} else {
					cb(null);
				}
			});
		});
	});
}
开发者ID:anuragagarwal561994,项目名称:browsix,代码行数:29,代码来源:rm.ts

示例2: function

            .forEach(d => {
                var directoryPath = path.join(definitelyTypedRoot, d);
                fs.readdir(directoryPath, function (err, files) {
                    if (err) throw err;

                    var tsFiles = [];
                    var testFiles = [];
                    var paramFile;

                    files
                        .map(f => path.join(directoryPath, f))
                        .forEach(f => {
                            if (fileExtensionIs(f, ".ts")) tsFiles.push(f);
                            else if (fileExtensionIs(f, ".tscparams")) paramFile = f;

                            if (fileExtensionIs(f, "-tests.ts")) testFiles.push(f);
                        });

                    if (testFiles.length === 0) {
                        // no test files but multiple d.ts's, e.g. winjs
                        var regexp = new RegExp(d + "(([-][0-9])|([\.]d[\.]ts))");
                        if (tsFiles.length > 1 && tsFiles.every(t => fileExtensionIs(t, ".d.ts") && regexp.test(t))) {
                            tsFiles.forEach(filename => {
                                importDefinitelyTypedTest(path.basename(filename, ".d.ts"), [filename], paramFile);
                            });
                        }
                        else {
                           importDefinitelyTypedTest(d, tsFiles, paramFile);
                        }
                    }
                    else {
                        testFiles.forEach(filename => {
                            importDefinitelyTypedTest(path.basename(filename, "-tests.ts"), [filename], paramFile);
                        });
                    }
                });
            })
开发者ID:001szymon,项目名称:TypeScript,代码行数:37,代码来源:importDefinitelyTypedTests.ts

示例3: dirs

export function dirs(absPath: string, cb: (err: Error, dirNames?: string[]) => any, asyncOpsLimit: number = ASYNC_OPS_LIMIT): any {
  fs.readdir(absPath, (err, files: string[]) => {
    if (err) {
      if (err.code === 'ENOENT') {
        // if path doesn't exist, it's not an error, just return []
        return cb(null, []);
      }
      return cb(err);
    }
    filterLimit(files, asyncOpsLimit, function truthTest(file: string, truthTestCb: (err, truthValue?: boolean) => void): void {
      fs.stat(join(absPath, file), (statErr, stats: fs.Stats) => {
        if (statErr) {
          return truthTestCb(statErr);
        }
        truthTestCb(null, stats.isDirectory());
      });
    }, function filteringDoneCb(filteringError, dirNames: string[]) {
      if (filteringError) {
        return cb(filteringError);
      }
      return cb(null, dirNames);
    });
  });
}
开发者ID:justin-calleja,项目名称:dirs,代码行数:24,代码来源:index.ts

示例4: getChildren

            getChildren(cb: IGetChildrenCallback): void {

                var fs = require('fs');
                //console.log(fs);

                fs.readdir(this.full_path, (err, files) => {
                    // @files contains the plain file names of the children; we need to make these into fileEntry's
                    console.log(files);
                    console.log("files");
                    var child_list = [];
                    files.forEach((val, index) => {
                        var stats = fs.statSync(this.full_path);
                        if (stats.isFile()) {
                            var file_entry = new FileEntry(val, this.full_path, this.full_path);
                            child_list.push(file_entry);
                        } else if (stats.isDirectory()) {
                            var dir_entry = new DirEntry(val, this.full_path, this.full_path);
                            child_list.push(dir_entry);
                        }
                    });
                    cb(child_list);
                });

            }
开发者ID:niagr,项目名称:reels-nwjs,代码行数:24,代码来源:fs.ts

示例5: readdir

	return new Promise<Array<string>>(( resolve, reject ) => {
		let paths:Array<string> = [];
		readdir(dir, ( error, files ) => {

			Promise.all(
				files.map(file => {
					const path = join(dir, file);

					if (file === 'node_modules') {
						return Promise.resolve([]);
					}

					return isDirectory(path)
						.then(isDir => isDir ? readFilesFromDir(path) : Promise.resolve( [ path ]));

				})
			)
				.then(( filesPerDir:Array<any> ) => {
					resolve([].concat(...filesPerDir))
				})
				.catch(error => reject(error));
			
		});
	});
开发者ID:ChristianKohler,项目名称:NpmIntellisense,代码行数:24,代码来源:util.ts

示例6: constructor

  constructor() {
    const options: InterfaceSettings = {
      settings: {
        lang: 'en',
        commands: [
          { name: '!set', fnc: 'setValue', permission: permission.CASTERS },
          { name: '!_debug', fnc: 'debug', permission: permission.CASTERS },
          { name: '!enable', fnc: 'enable', permission: permission.CASTERS },
          { name: '!disable', fnc: 'disable', permission: permission.CASTERS },
        ],
      },
      ui: {
        lang: {
          type: 'selector',
          values: [],
        },
      },
      on: {
        change: {
          lang: ['onLangUpdate'],
        },
        load: {
          lang: ['onLangLoad'],
        },
      },
    };

    super(options);

    // update lang values
    readdir('./locales/', (err, f) => {
      if (typeof this._ui.lang === 'object' && this._ui.lang.type === 'selector') {
        this._ui.lang.values = [...new Set(f.map((o) => o.split('.')[0]))];
      }
    });
  }
开发者ID:sogehige,项目名称:SogeBot,代码行数:36,代码来源:general.ts

示例7:

 let relativePaths = await mio.promise<string[]>(callback => fs.readdir(fileOrFolderPath, callback));
开发者ID:HigorSevilha,项目名称:mangarack,代码行数:1,代码来源:fileService.ts

示例8: handleResult

 return new Promise<string[]>((resolve, reject) => {
     fs.readdir(path, (error, children) => handleResult(resolve, reject, error, normalizeNFC(children)));
 });
开发者ID:voodoos,项目名称:vscode-extension-samples,代码行数:3,代码来源:extension.ts

示例9: function

        fs.stat(path, function (err: any, stats: any) {
            if (err) {
                cb(err, stats);
                return;
            }
            if (stats.isFile()) {
                fs.unlink(path, function (err: any) {
                    if (err) {
                        cb(err, null);
                    } else {
                        cb(null, true);
                    }
                    return;
                });
            } else if (stats.isDirectory()) {
                // A folder may contain files
                // We need to delete the files first
                // When all are deleted we could delete the 
                // dir itself
                fs.readdir(path, function (err: any, files: any) {
                    if (err) {
                        cb(err, null);
                        return;
                    }
                    var f_length = files.length;
                    var f_delete_index = 0;

                    // Check and keep track of deleted files
                    // Delete the folder itself when the files are deleted

                    var checkStatus = function () {
                        // We check the status
                        // and count till we r done
                        if (f_length === f_delete_index) {
                            fs.rmdir(path, function (err: any) {
                                if (err) {
                                    cb(err, null);
                                } else {
                                    cb(null, true);
                                }
                            });
                            return true;
                        }
                        return false;
                    };
                    if (!checkStatus()) {
                        for (var i = 0; i < f_length; i++) {
                            // Create a local scope for filePath
                            // Not really needed, but just good practice
                            // (as strings arn't passed by reference)
                            (function () {
                                var filePath = path + '/' + files[i];
                                // Add a named function as callback
                                // just to enlighten debugging
                                fs.removeRecursive(filePath, function removeRecursiveCB(err: any, status: any) {
                                    if (!err) {
                                        f_delete_index++;
                                        checkStatus();
                                    } else {
                                        cb(err, null);
                                        return;
                                    }
                                });

                            })()
                        }
                    }
                });
            }
        });
开发者ID:into-cps,项目名称:intocps-ui,代码行数:70,代码来源:custom-fs.ts

示例10: function

fs.readdir(folder, function(err, files) {
	if (err) throw err;
	console.log(files);
	for (var f=0; f<files.length; f++) {
		var filepath = path.resolve(folder+"\\"+files[f]);
		//fs.stat(), fs.lstat() and fs.fstat() and their synchronous counterparts are of this type.
		//stats.isDirectory()
		if (filepath.indexOf(".xls")!=filepath.length-4)
			continue;
		
		console.log("filepath: "+filepath+"\n");
		var book = xl.Workbooks.Open(filepath);
		var nb_sheet = book.Worksheets.Count;
		console.log("nb_sheet: "+nb_sheet);
		for (var s=0; s<nb_sheet; s++) {
			var sheet = book.Worksheets(s+1);
			console.log("sheet: "+(s+1)+"/"+nb_sheet+" "+sheet.Name);
			
			// find total span of content
			var xlCellTypeLastCell =11;
			var rng_bottom_right = sheet.Cells(1,1) .SpecialCells(xlCellTypeLastCell)
			var n = rng_bottom_right.Row, 
				m= rng_bottom_right.Column;
			console.log(n+" x "+m);
			// Range("B4").End(xlUp).Select  go to end of contiguous range
			
			for (var j=0; j<m; j++) {
				for (var i=0; i<n; i++) {
					var rng = sheet.Cells(i+1,j+1);
					var addr = ""+rng.Address;
					if (rng.HasArray()==true) {
						//console.log(rng.Address+" AF "+JSON.stringify(rng.HasArray())+" "+rng.CurrentArray().Cells(1,1).Address );
						var array_addr = ""+rng.CurrentArray().Cells(1,1).Address
						if (addr==array_addr)
						//if (rng.CurrentArray().Cells(1,1).Address==rng.Address)
							console.log(rng.CurrentArray().Address+" {} "+rng.FormulaArray);
						//rng.FormulaArray
					} else if (rng.HasFormula()==true) {
						var txt = ""+rng.FormulaR1C1;
						var rng0 = rng;
						if (i>0 && (""+sheet.Cells(i, j+1).FormulaR1C1)==txt)
							continue; // already used
						while ((""+sheet.Cells(i+1+1, j+1).FormulaR1C1)==txt)
							i++;
						var rng1 = sheet.Cells(i+1, j+1);
						var rng = sheet.Range(rng0, rng1);
						if (""+rng0.Address != ""+rng1.Address) {
							console.log(rng.Address+" [] "+rng0.FormulaR1C1);
						} else {
							console.log(rng.Address+"    "+rng.FormulaR1C1);
						}
					} else if (rng.Text!="") {
						// Value2 property doesn't use the Currency and Date 
						console.log(rng.Address+" VAL "+rng.Text);
					}
				}
			}
		}
	
		book.Close();
		break;
	}
});
开发者ID:kljh,项目名称:grid,代码行数:63,代码来源:excel_com.ts


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