-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateDirectoryWindows.py
More file actions
31 lines (24 loc) · 1.07 KB
/
createDirectoryWindows.py
File metadata and controls
31 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
# Date: 2/5/2015
# File name: createDirectory.py
# Python Version: 2.X, Windows
# Description: This script shows the example of how concatenation works in python, utilizing the os module to check a directory
# and create it if it does not exist, and opening and closing a file for writing.
#
# This is nothing too difficult, and you can certainly add more functionality to it if you wish.
# One idea is to build this whole example into an object with subsequent methods.
import os, datetime
# Create the file name
baseFileName = "12345"
app="someAppName"
dateTimeStamp = datetime.date.today()
# This directory needs to exists. It is the parent directory that will house the datafiles.
targetDirectory = "C:\datafiles"
targetfileName = str(baseFileName)+"_"+app+"."+str(dateTimeStamp)+".txt"
fullPathToFile = targetDirectory+"\\" + targetfileName
print "FileName: " + fullPathToFile
# Check base path. If it does not exist, create it.
if not os.path.isdir(targetDirectory):
os.makedirs(targetDirectory)
file = open(fullPathToFile,'w')
file.write("This is a test.")