Вот несколько способов проверить существование папки:
-
Метод 1. Использование модуля
osв Python:import os folder_path = '/path/to/folder' if os.path.exists(folder_path) and os.path.isdir(folder_path): print("Folder exists!") else: print("Folder does not exist!") -
Метод 2. Использование класса
Pathиз модуляpathlibв Python:from pathlib import Path folder_path = Path('/path/to/folder') if folder_path.exists() and folder_path.is_dir(): print("Folder exists!") else: print("Folder does not exist!") -
Метод 3. Использование модуля
fsв Node.js:const fs = require('fs'); const folderPath = '/path/to/folder'; if (fs.existsSync(folderPath) && fs.lstatSync(folderPath).isDirectory()) { console.log("Folder exists!"); } else { console.log("Folder does not exist!"); } -
Метод 4. Использование класса
Fileв Java:import java.io.File; String folderPath = "/path/to/folder"; File folder = new File(folderPath); if (folder.exists() && folder.isDirectory()) { System.out.println("Folder exists!"); } else { System.out.println("Folder does not exist!"); } -
Метод 5. Использование метода
Directory.Existsв C#:using System; using System.IO; string folderPath = "/path/to/folder"; if (Directory.Exists(folderPath)) { Console.WriteLine("Folder exists!"); } else { Console.WriteLine("Folder does not exist!"); }