File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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." )
You can’t perform that action at this time.
0 commit comments