Postoji li datoteka ili ne, pitanje je tad

bash.sh

  • if [   -f "datoteka.txt" ]; then echo "Postoji"   ; fi
  • if [ ! -f "datoteka.xyz" ]; then echo "Ne postoji"; fi

batch.cmd

  • if     exist datoteka.txt echo "Postoji"
  • if not exist datoteka.xyz echo "Ne postoji"

javascript.js

powershell.ps1

  • if    (Test-Path -Path .\direktorij\datoteka.txt -PathType Leaf)  {write-host "Postoji"}
  • if (! (Test-Path -Path .\direktorij\datoteka.xyz -PathType Leaf)) {write-host "Ne postoji"}

python.py

  • import pathlib; file=pathlib.Path("datoteka.txt"); if file.exists (): print ("Postoji") 
  • import pathlib; file=pathlib.Path("datoteka.xyz"); if not file.exists (): print ("Ne postoji") 

ili

  • import os; if not os.path.exists("datoteka.txt"): print ("Ne postoji")

file exists fileexists xfile xexists xfileexists directory xdirectory datoteka xdatoteka xpostoji if exists if not exists

image_pdfimage_print