Python file detection 📁
Ғылым және технология
Python file detection handling tutorial example explained
#python #file #handling
import os
path = "C:\\Users\\User\\Desktop\\test.txt"
if os.path.exists(path):
print("That location exists!")
if os.path.isfile(path):
print("That is a file")
elif os.path.isdir(path):
print("That is a directory!")
else:
print("That location doesn't exist!")
Пікірлер: 70
import os path = "C:\\Users\\User\\Desktop\\test.txt" if os.path.exists(path): print("That location exists!") if os.path.isfile(path): print("That is a file") elif os.path.isdir(path): print("That is a directory") else: print("That location doesn't exist!")
@StrangerDanger352
2 жыл бұрын
it's not detecting bro help me
@irfanhakim4617
2 жыл бұрын
@@StrangerDanger352 What ide you using? is it replit?
@StrangerDanger352
2 жыл бұрын
@@irfanhakim4617 i am using pycharm it's detecting now😁
@irfanhakim4617
2 жыл бұрын
@@StrangerDanger352 GREAT! HAPPY CODING!🎉
@StrangerDanger352
2 жыл бұрын
@@irfanhakim4617 which ide do you use?
This just gave me ideas for file management and sorting on my pc. Thank you Bro Code!
the only KZread channel that matters
Bro gonna ignore the fact he has a "nuclear launch codes" folder..
@szymongrzebyk5948
2 ай бұрын
True
appreciate your efforts man!
0:57 nuclear launch codes lol
See u dropping sum vids here..thank you!!:) keep em coming buddy!! Wrkn through new java tutorial now...teach me yoda!!!
thanks for teaching python in this easy method I wish i could meet you for once you are a legend bro(or whatever your REAL name is)😉😉😉
Great tutorial !! :) Thx
i want that Nuclear launch code😈.. just kiddin..im loving every minute of your videos
Great tutorial!
I really liked this! But just so I didnt have to change the path manually I changed the path variable to path = input("What is the path!: "), Ik it does the same thing but I just thought I would say that line of code: import os path = input("What is the path!: ") if os.path.exists(path): print("That location exist!") if os.path.isfile(path): print("This is a file!")
Thanks for the video bro
Thanks bro!
Why does this guy have the nuclear launch codes on his desktop 💀 💀 💀
big thanks bro
love you bro
Solid!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Amazing
Awesome
Wow!
💖💖💖
you saved me thanks
ty
Hey bro !! What's up
thank you brotha
So, I made the text file on desktop, and copied the location as highlighted in the video, however for some reason it says the location doesn't exist, which is odd...
@jcmkt9661
2 жыл бұрын
delete the ".txt" in the file name in your computer. try it
@rihabhassanha8200
Жыл бұрын
Same
@jarenventures
Жыл бұрын
@@jcmkt9661 how do i call a folder? just hitting folder didn't work
@J11_boohoo
6 ай бұрын
Same
Radhe Radhe Sanatan Hi Satya Hai Jai To All Gods & Godesses Jai Baba Farid Ji Radhaswami Ji
Nice nuclear launch codes 🤣
Your favourite game probably is Broforce.
Hi there does this code work differently for different versions of windows as mine say's that it could not detect a file even though I created one and copied it exactly into my code.
Hey Bro, quick question: Was there a specific reason you didn't mention raw string literals (r"This/Is/MyPath") to avoid escaping every single slash?
@banglawarlock3947
Жыл бұрын
maybe because when you copy a path its backslash by default. if you change them to normal slash, you nend to press backspace then enter a new slash which seems like so much more work than entering just one more backslash
A Nuclear launch codes on his desktop?
YT algorithm comment
I'm using a Mac and I'm having problems to detect files and folders both: import os a="Macintosh HD ▸ Users ▸ ayushtshong ▸ Desktop" if os.path.exists(a): print("the file exists") else: print("it doesn't)
@techlace1195
Жыл бұрын
hey, i don't know if you still need answer but i wanna share how to solve this problem. choose the file and press command+i, then you;ll get info about your file copy the path as pathname. it'll be something like this: /Users/abcd/Documents/Photos/Efg. thenk just paste this path. hope i'll help smbd
Hello there, its not working for me, it has no any "exists" or "not exists" i made the file in different directories and still nothing, the program run blank with a "Process finished with exit code 0" and nothing happens. Any suggestions?
@hippopotamus_nr2587
2 жыл бұрын
did you print it? (probs yes but just to be sure)
@norbertjanovics5655
2 жыл бұрын
@@hippopotamus_nr2587 yea i did, well i made a new file in the same project, and this code works in the first file, but not in the new one... so i really dont know...
@hippopotamus_nr2587
2 жыл бұрын
@@norbertjanovics5655 then i don't get it, weird that it can run a file program for the first one, but not for the second. maybe it has to do with the type of file, but i don't know a lot about that sort of thing. hopefuly someone with more experience can come help you
@CarlosEduardo-nb4we
2 жыл бұрын
I have the same problem, did you solve it?
@hippopotamus_nr2587
2 жыл бұрын
@@CarlosEduardo-nb4we i didn't, no
nuclear launch codes 😆
Can we know if a file exist when we don't know the file location path??!
Yo bro code, if i dont use path as my variable the program dies why is that?
@oreoplushie6231
11 ай бұрын
because the variable is the one telling the program which file to look for.
@Algeriawindows69
8 ай бұрын
it tells it where is the file
🛋😌🤓
Bro
Radhe Radhe Sanatan Hi Satya Hai Jai To All Gods & Godesses Jai Baba Farid Ji Radhaswami Ji
Radhe Radhe Sanatan Hi Satya Hai Jai To All Gods & Godesses Jai Baba Farid Ji Radhaswami Ji
Radhe Radhe Sanatan Hi Satya Hai Jai To All Gods & Godesses Jai Baba Farid Ji Radhaswami Ji