Skip to main content

DELETE FILE USING PYTHON.HOW TO DELETE FILE USING PYTHON.

DELETE FILE USING PYTHON.HOW TO DELETE FILE USING PYTHON.

TO DELETE FILE IN PYTHON PROGRAMME YOU NEED IMPORT A PRE-INSTALLED OR IN BUILT MODULE WHICH NAME IS "OS".

                                              import os

THEN YOU SIMPLY CALL OS MODULE TO REMOVE FILE.

                          import os

                         os.remove("file name with path")   LIKE THIS
                     
                        os.remove("file.txt")




IF YOU WANT TO VERIFY THEN YOU CAN USE IF ELSE.
USING IF ELSE YOU CAN EASILY VERIY THAT THE FILE IS FOUND OR NOT AND REMOVE OR NOT.

  LIKE THIS:

           import os
           if os.path.exists("new.txt"):
                             os.remove("new.txt")
                             print("success")

          else:
                print("Not Found")

  IN THIS CASE OUR FILE NAME IS "NEW.TXT".

FOR FOUND:




FOR NOT FOUND:






IN THIS YOU CAN DELETE FILE USING PYTHON PROGRAMME.



Comments

Popular posts from this blog

SPEECH RECOGNITION USING PYTHON-SPEECH TO TEXT OR SPEECH

PYTHON SPEECH TO TEXT OR  SPEECH-RECOGNITION USING PYTHON : STEP -1 :               PYTHON LIBRARIES                      Speech_Recognition.(pip install SpeechRecognition)       Note : You Must Connect To The Internet Step#2:          Open your favorite IDE, we are choosing IDLE , and  write the below code:             For English Language:                   import speech_recognition as sr               r=sr.Recognizer()               with sr.Microphone() as source:                     print("Listening......")                     audio=r.listen(source) ...

DATA TYPES OF PYTHON

DATA TYPES OF PYTHON.PYTHON DATA TYPE. PYTHON DATA TYPE 1.  STRING DATA TYPE. 2.  INTEGER DATA TYPE. 3.  LIST DATA TYPE. 4.  TUPLE DATA TYPE. 5.  DICTIONARY DATA TYPE. 6.  BOOLEAN DATA TYPE. EXAMPLE: 1. a = "Hello World"----------------------------------------->>>>> str 2. b = 20---------------------------------------------------->>>>> int 3. c = ["apple", "banana", "cherry"]------------------------->>>>> list 4. d = ("apple", "banana", "cherry")------------------------->>>>> tuple 5. e = {"name" : "John", "age" : 36}------------------------->>>>> dict 6. f = True-------------------------------------------------->>>>> bool  NOTE:    You can get the data type of any object by using the  type()  function which is inbuilt function of python. T...

Hello World in java

       Hello World in java First create a class.Here the class name is Demo.Then Create the main method which is  represents the starting point of the program.On the main class use print statement to print something using "  System.out.println()". The Code Is:   public class Demo { public static void main(String args[]) { System.out.println("Hello world"); } }