-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckfile.py
77 lines (65 loc) · 1.97 KB
/
checkfile.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 9 08:07:22 2019
@author: USER
"""
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 9 05:30:15 2019
@author: USER
"""
import os
#import os.path
if os.path.isfile('../random-numbers.txt'):
print('found')
else:
print('Not found')
#Function to count number of files in a folder
def directory(path,extension):
list_dir = []
list_dir = os.listdir(path)
count = 0
for file in list_dir:
if file.endswith(extension): # eg: '.txt'
count += 1
return count
print (directory('../input', '.txt'))
with open("copy.txt", "w") as file:
file.write("Your text goes here")
# Method 1
#f = open("Path/To/Your/File.txt", "w") # 'r' for reading and 'w' for writing
#f.write("Hello World from " + f.name) # Write inside file
#f.close() # Close file
#
## Method 2
#with open("Path/To/Your/File.txt", "w") as f: # Opens file and casts as f
# f.write("Hello World form " + f.name) # Writing
# f.close() # Close file
#
##Method3
#f = open('file.txt','w')
#a = input('is python good?')
#f.write('answer:'+str(a))
#f.close()
#
##Method3 modify
#with open('spam.txt', 'a') as f:
# f.write(string_output)
#cur_path = os.path.dirname(__file__)
#new_path = os.path.relpath('..\\input\\input-1.txt', cur_path)
#if (new_path):
#print (new_path)
#else:
# print('File Not Found')
#d = os.getcwd() # Get the working directory
##os.chdir("..") #Go up one directory from working directory
#o = [os.path.join(d,o) for o in os.listdir(d) if os.path.isdir(os.path.join(d,o))] #Tupple List of all directory
#!Below code search the tuple for the directory i want and open the file in that directory
#print(o)
#for item in o:
#if os.path.exists(item):
#file = item + '\\inpt-1.tx'
##print(item)
#print('found')
#else:
#print('file not find')