Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7fcaa8

Browse files
committed
Windows version of createDirectory.py
Added a windows version.
1 parent 93ec9a3 commit f7fcaa8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

createDirectoryWindows.py

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

0 commit comments

Comments
 (0)