Skip to content

Commit e3b28cc

Browse files
committed
Merge pull request geekcomputers#1 from geekcomputers/master
update from geekcomputers/Python/master
2 parents ee9ff4b + 3ab6f7e commit e3b28cc

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
Here is some more detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at [email protected].
22

3-
In the scripts the comments etc are lined up correctly when they are viewed in Notepad++. This is what I use to code Python scripts.
3+
In the scripts the comments etc are lined up correctly when they are viewed in [Notepad++](https://notepad-plus-plus.org/). This is what I use to code Python scripts.
44

5-
batch_file_rename.py - This will batch rename a group of files in a given directory, once you pass the current and new extensions
5+
- `batch_file_rename.py` - This will batch rename a group of files in a given directory, once you pass the current and new extensions.
66

7-
`create_dir_if_not_there.py` - Checks to see if a directory exists in the users home directory, if not then create it
7+
- `create_dir_if_not_there.py` - Checks to see if a directory exists in the users home directory, if not then create it.
88

9-
`dir_test.py` - Tests to see if the directory testdir exists, if not it will create the directory for you
9+
- `dir_test.py` - Tests to see if the directory `testdir` exists, if not it will create the directory for you.
1010

11-
`env_check.py` - This script will check to see if all of the environment variables I require are set
11+
- `env_check.py` - This script will check to see if all of the environment variables I require are set.
1212

13-
`fileinfo.py` - Show file information for a given file
13+
- `fileinfo.py` - Show file information for a given file.
1414

15-
`folder_size.py` - This will scan the current directory and all subdirectories and display the size.
15+
- `folder_size.py` - This will scan the current directory and all subdirectories and display the size.
1616

17-
`logs.py` - This script will search for all `*.log` files in the given directory, zip them using the program you specify and then date stamp them
17+
- `logs.py` - This script will search for all `*.log` files in the given directory, zip them using the program you specify and then date stamp them.
1818

19-
`move_files_over_x_days.py` - This will move all the files from the src directory that are over 240 days old to the destination directory.
19+
- `move_files_over_x_days.py` - This will move all the files from the src directory that are over 240 days old to the destination directory.
2020

21-
`nslookup_check.py` - This very simple script opens the file `server_list.txt` and the does an nslookup for each one to check the DNS entry
21+
- `nslookup_check.py` - This very simple script opens the file `server_list.txt` and the does an nslookup for each one to check the DNS entry/
2222

23-
`osinfo.py` - Displays some information about the OS you are running this script on
23+
- `osinfo.py` - Displays some information about the OS you are running this script on.
2424

25-
`ping_servers.py` - This script will, depending on the arguments supplied will ping the servers associated with that application group.
25+
- `ping_servers.py` - This script will, depending on the arguments supplied will ping the servers associated with that application group.
2626

27-
`ping_subnet.py` - After supplying the first 3 octets it will scan the final range for available addresses
27+
- `ping_subnet.py` - After supplying the first 3 octets it will scan the final range for available addresses.
2828

29-
`powerdown_startup.py` - This goes through the server list and pings the machine, if it's up it will load the putty session, if its not it will notify you.
29+
- `powerdown_startup.py` - This goes through the server list and pings the machine, if it's up it will load the putty session, if its not it will notify you.
3030

31-
`puttylogs.py` - Zip up all the logs in the given directory
31+
- `puttylogs.py` - Zip up all the logs in the given directory.
3232

33-
`script_count.py` - This scans my scripts directory and gives a count of the different types of scripts
33+
- `script_count.py` - This scans my scripts directory and gives a count of the different types of scripts.
3434

35-
`script_listing.py` - This will list all the files in the given directory, it will also go through all the subdirectories as well
35+
- `script_listing.py` - This will list all the files in the given directory, it will also go through all the subdirectories as well.
3636

37-
`testlines.py` - This very simple script open a file and prints out 100 lines of whatever is set for the line variable
37+
- `testlines.py` - This very simple script open a file and prints out 100 lines of whatever is set for the line variable.

create_dir_if_not_there.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Script Name : create_dir_if_not_there.py
22
# Author : Craig Richards
33
# Created : 09th January 2012
4-
# Last Modified :
4+
# Last Modified : 22nd October 2015
55
# Version : 1.0
6-
# Modifications :
6+
# Modifications : Added exceptions
77

88
# Description : Checks to see if a directory exists in the users home directory, if not then create it
99

10-
import os # Import the OS module
11-
home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory
12-
print home # Print the location
13-
if not os.path.exists(home+'/testdir'): # Check to see if the directory exists
14-
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
10+
import os # Import the OS module
11+
try:
12+
home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory
13+
print home # Print the location
14+
if not os.path.exists(home+'/testdir'):
15+
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
16+
except Exceptions as e:
17+
print e

0 commit comments

Comments
 (0)