Created
May 23, 2017 03:29
-
-
Save alexhudici/c88fcf6ebab17b5209fd7206f02ca3a9 to your computer and use it in GitHub Desktop.
Python OS actions created by alexhudici - https://repl.it/ILzI/19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Use this space to try out ideas and free code ### | |
#!/usr/bin/python | |
import json | |
import os | |
import time | |
import sys | |
import shutil | |
testdir = "/home/runner/testdir1" | |
# Create a link in the file system | |
def createLink(sourceDirectory, targetLink ): | |
if not os.path.exists(sourceDirectory): | |
os.makedirs(sourceDirectory) | |
if not os.path.exists(targetLink): | |
print("Creating link : " + sourceDirectory + " --> " + targetLink + "\n") | |
path,file = os.path.split(targetLink) | |
if not os.path.exists(path): | |
os.makedirs(path) | |
os.symlink(sourceDirectory, targetLink) | |
else: | |
existingLink = os.readlink(sourceDirectory) | |
if sourceDirectory == existingLink: | |
print("File exists at " + targetLink + ". This is ok.") | |
else: | |
return 1 | |
return 0 | |
print(os.listdir(os.getcwd())) | |
print(os.listdir(testdir)) | |
if os.path.exists(testdir): | |
try: | |
shutil.rmtree(testdir) | |
except: | |
print("durf") | |
print("ih") | |
print(testdir + " exists after delete: " + str(os.path.exists(testdir))) | |
os.makedirs(testdir) | |
print(testdir + " exists after create: " + str(os.path.exists(testdir))) | |
os.makedirs(testdir + "/path1") | |
os.makedirs(testdir + "/path2") | |
os.makedirs(testdir + "/path3") | |
os.makedirs(testdir + "/path4") | |
print("after make ", os.listdir(testdir)) | |
print("after make ", os.listdir("/home/runner")) | |
print(createLink(testdir + "/path2", testdir + "/path1")) | |
print("after path2->path1 ", os.listdir(testdir)) | |
print(createLink(testdir + "/path5", testdir + "/path4")) | |
print("after path5 -> path4 ", os.listdir(testdir)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment