Home > other >  how to add condition if directory already exist in flutter
how to add condition if directory already exist in flutter

Time:11-23

I am creating a directory now I want to add a condition if the directory already exists. This is my code

                    if(name == ''){  
                        print('empty controller');
                      }
                      else{
                        print('succcci');

                        var path = "storage/emulated/0/zip/$name";
                        new Directory(path).create();
                      }

CodePudding user response:

You can use exists():

var path = "storage/emulated/0/zip/$name";

if(!await Directory(path).exists()){
   //need to create directory
   Directory(path).create();
}
  • Related