An warware: duba node idan akwai fayil

Babban matsalar bincika idan akwai fayil shine cewa yana iya zama a hankali.

var fs = require('fs');

if (fs.existsSync('file.txt')) {
  // do something
}

Wannan lambar tana duba idan fayil mai suna 'file.txt' yana cikin kundin adireshi na yanzu. Idan ya yi, to, lambar da ke cikin idan bayanin zai gudana.

aiki tare da fayiloli

Akwai ฦดan hanyoyi don aiki tare da fayiloli a JavaScript. Hanyar gama gari ita ce amfani da API ษ—in Fayil. Hakanan zaka iya amfani da abubuwan FileReader da FileWriter don karantawa da rubuta fayiloli.

idan akwai fayil

idan (file.exists()) {// yi wani abu tare da fayil }

Shafi posts:

Leave a Comment