

Thank you all for being so generous with your time. I wish I could check all of you as the answer, but I bothered the most so I gave it to him. I also used the error catching method recommended here.
#Wincatalog youtube code
So I spent three days learning to write two lines of code (I know the lesson is more than that). What was happening is that there were some files that didn't have that regex expression so I assumed Python would skip them. Last Edit: I got it to work using mostly the code as written. Thank you all for the help so far.Įdit 2: This is for the answer below: import globįor fname in glob.glob("/directory/structure/here/*.txt"): I was going to post this as a comment to the answer but I wanted to include so much code that this seemed to be a better way to express the `new' problem. When I tried copying and pasting code line for line, it came up with the same error. However, when I add in the nname = oup(0) line after the original tname = rg.search(contents) and change around the print function to reflect the change, it gives me the following error: AttributeError: 'NoneType' object has no attribute 'group'. Then this prints out the byte location of the the pattern - signifying that the regex pattern is correct. When I manipulate that to fit the glob.glob structure, and make it like this: import globįor fname in glob.glob("\file\structure\here\*.txt"): I've spent the last few hours looking reading documentation and parsing through StackOverflow but it doesn't seem like anyone has quite had this issue before - or at least they haven't asked about their problem.Ĭan anyone point me in the right direction?ĮDIT 1: When I create the regex pattern using this website, it creates bulky but seemingly workable code: import re

This seems like it should be easy, so much so that I feel silly writing this question. I've thought through many ways of accomplishing this task but it seems like easiest and most efficient way would be to create a loop that finds the unique phrase in a file, assigns it to a variable and use that variable to rename the file before moving to the next file.
#Wincatalog youtube how to
I've looked at the os module and I understand howĬould be useful but I don't understand how to combine those functions with intratext manipulation functions like linecache or general line reading functions. The phrase is not always on the same line (though it doesn't deviate that much) but it always is in the same format and with the No.

I would like to replace the arbitrary file name with that given phrase for every text file. Put differently and more specifically, I have a few hundred text files with arbitrary names but within each file is a unique phrase (something like No. txt files in a directory according to a specific phrase in each given text file.
#Wincatalog youtube series
Using Python, I'm trying to rename a series of.
