## Monday, June 1, 2020

Solution Exercise 52 creating,moving and renaming a file in the desktop

#### Exercise 52

1.  Write a python program that allowing you to create a directory in the desktop called myDir
2. Write  a Python program allowing you to create a file in the desktop named myFile.txt and write it the following lines:
here is an example of a text file
this file was created with python
we can write on this file
3. Write  a Python program allowing you to moving myFile.txt in the  directory  myDir.

#### Solution

Question1 ``` ```
``````import os

# get user name
user = os.getlogin()

#getting the desktop directory
d = "C:/users/" + user + "/desktop/"

# creating directory myDir in the desktop
os.mkdir(d + "myDir/")
``````
Question2 ``` ```
``````import os

# get user name
user = os.getlogin()

#creating myFile.txt in the desktop
myfile = "C:/users/" + user + "/Desktop/myFile.txt"

#opening  myFile.txt in writing mode w
f = open(myfile , 'w')

#writing on myFile.txt
f.write("here is an example of a text file\n this file was created with python\n we can write on this file")
f.close()
``````
Question3``` ```
``````user = os.getlogin()

#getting the desktop directory

# moving myFile.txt to myDir directory

os.rename("C:/Users/" +user + "/Desktop/myFile.txt" , "C:/Users/" +user + "/Desktop/myDir/myFile.txt")

``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi