samedi 27 juin 2015

How to create regular expression starting with different directory name in Python

Currently I am taking directory path as input from the user. The path will be different for each user(dir_name will be different)

/file/perm/perm13/user123/dir_name/ 

while the structure inside dir_name is same for all users given as below:

tar1 tar2 tar3 tar4 tar5 tar6 source

In each tar, three folders are there: build collateral fix in collateral: I have three different files

 _base.txt, _fullbase.txt and _skip.txt 

I also need corresponding .dot files from source/projectfiles/params/tar_base.dot | tar_fullbase.dot | tar_skip.dot

Here is what I need to do:
1. Take input from user 2. One by one- go into the targets. (tar1 -> tar2 -> tar3 ->tar4 ->tar5) 3. For each tar, search for collateral folder 4. and in collateral folder search for all three .txt files 5. for each .txt file search for corresponding .dot file

currently I do following: I take path for txt from the user

txtfilepath = raw_input (" Please provide file path for the desired txt")
dotfilepath = raw_input (" Please enter corresponding .dotfilepath")
<directory path>/<tar1>/collateral/<xyz_base.txt)

The regex:

platform = re.search("?<=/collateral/).(?="_(base|fullbase|skip)\.txt)",txtfilepath).group(0)

can some python geek help?

Aucun commentaire:

Enregistrer un commentaire