Posts: 52
Threads: 26
Joined: May 2019
Hi,
I have a file name config_file_data302, I want to get the location of the file name to contain "congfig_file" in a given directory (avoid hidden file i.e, '.','..'). and write the same data in another file config_data303 in the same directory.
Posts: 606
Threads: 3
Joined: Nov 2016
Posts: 52
Threads: 26
Joined: May 2019
May-19-2019, 09:23 AM
(This post was last modified: May-19-2019, 12:47 PM by SriMekala.)
Actually, I defined my path as:
#define file name and write to webservicedata.csv
import pandas as pd
my_path='D:\pythonCodes\myproject'
f=open('webservicedata.csv','w',newline='')
f.write(data)
f.close()
#read partial data from above file and write into another file in the same director(absolute directory)
df=pd.read_csv("D:\pythonCodes\myproject\webservicedata.csv")
df1=df[:10]
filename='config_file_data02'
df1.to_csv(my_path,filename,index=False,header=False) I want to trace the full file name match the partial file name as "config_file" and its full path.
Posts: 1,950
Threads: 8
Joined: Jun 2018
I observe on row #3 my_path=='D:\pythonCodes\myproject' . I think that this is not intended this way because on row #11 you try to use my_path which will not exist.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 52
Threads: 26
Joined: May 2019
I already defined in row3, but won't it exists when it comes to row11? how to retain it if not exists?
Posts: 1,950
Threads: 8
Joined: Jun 2018
(May-19-2019, 11:32 AM)SriMekala Wrote: I already defined in row3
There is == so it is not assignment:
>>> 2 == 2
True
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 52
Threads: 26
Joined: May 2019
Its typo error, sorry I did not notice that. Now corrected,
Posts: 52
Threads: 26
Joined: May 2019
Hi,
In a given directory there will always exist only one file contains the partial name"config_file", and I want to match which file name contains partial file name "config_file" and grab that full name of the file. Suppose,
in a given directory:
"D:\mainfolder"
maybe there are
"initial.csv"
"final.csv"
"config_file_data.csv"
"data.csv"
out of all CSV files, the file contains "config_file" is "config_file_data.csv", and I want to report this file name. Actually, periodically the files are updated, and but always there will be one file contain the name "config_file", and that I want to catch.
Posts: 1,950
Threads: 8
Joined: Jun 2018
May-19-2019, 07:40 PM
(This post was last modified: May-19-2019, 07:40 PM by perfringo.)
It's unclear how code supposed to work, but there is glob:
glob.glob('*config_file*') # returns list of matching filenames in current directory
glob.glob('*config_file*')[0] # if you are sure that there is only one matching file
glob.glob(r'D:\mainfolder\*config_file*') # should work, I am not using Windows, returns list of paths
glob.glob(r'D:\**\*config_file*', recursive=True) # search recursively in D subfolders
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
|