473,659 Members | 3,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compare filenames in directory against a textfile list

3 New Member
I have a text file that has a frequently-changing list of filenames in it.

exampleList.txt :
Expand|Select|Wrap|Line Numbers
  1. fee.doc
  2. fye.doc 
  3. foe.doc
  4. fum.doc
  5. ftangftang_ole_biscuitbarrel.doc
I want to return True if the list exactly matches the files in a given directory.
I want to return False if the directory contains files that are not in the list, and also if it only contains some but not all of the files in the list.

I know how to read the contents of the file into a variable, and I know how to read the directory listing into a variable. I know how to compare individual directory entries against the list, but no idea about comparing the entire directory listing at once against the textfile list. I've spent a stupidly huge amount of time on this already and I'm about ready to give up. Grr.
May 26 '10 #1
2 4824
dwblas
626 Recognized Expert Contributor
You can test that with os.path.isfile( directory_and _file)
Docs are here http://docs.python.org/library/os.path.html
Also, you compare the length of the text file and the directory listing. If different, then they obviously are different. Finally then, loop through one of the lists (either text file records or directory listing) and delete from the other list if the file name is found in it. If you have any not found, or any left over then the two are different.
May 26 '10 #2
Glenton
391 Recognized Expert Contributor
So am I right in saying you have two lists, and want to know if they are equal or one's a subset?

You could then change both lists into sets, and use the set functions.

If this doesn't mean anything, then post back and I'll explain in more detail.
Jun 2 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2693
by: Tony Burger | last post by:
I'm trying to drag and drop files from a file list box to a directory list box (the two controls are not related). Does anyone have an examples of this? I've got the properties setup correctly on the two controls and I'm starting the OLEDrag method of the file list box using the mouse down event. This calls the OLEStartDrag where I am attempting to get the Data control object setup. I think this is where my problem may be. The OLEDragDrop...
1
2407
by: Jeffrey Sheldon via SQLMonster.com | last post by:
SQL gurus... I have one table of items that is the master file. We will call this Table A. I have another table that contains few, some or all items from Table A. We will call this Table B. I want to run a query that compares the list of items on Table B against the master list on Table A.
5
3454
by: jnikle | last post by:
I have two completely unrelated tables, one for reviews and another for pay periods. The reviews table has a review date in it, and the pay periods table is just a list of the beginnings of pay periods. What I need to do is take a given review date and find out which date in my pay periods table it's closest to, above or below. Any help is greatly appreciated. -Josh
3
15442
by: Patrick Johnson | last post by:
Under visual basic there used to be a directory tree list box and file list box controls that could be placed on a form and linked together. Is there anything similar for C# or VB.net, I couldn't find anything...
5
37809
by: Jason | last post by:
Is there a mechanism in VB.NET that allows something like: If myVar In ("A","B","C") Then... The way I'm doing it now is: Select Case myVar Case "A","B","C" Or like this:
2
7791
by: Mirovk | last post by:
I am having problems making a comparison into my asp program when I compare against a bit field. the sintaxis used was: if (rs_cu("bt_nac") <1) then ....... I made the query using the query analyzer and saw that the field value was NULL so I made the question
1
6886
by: dcruncher4 | last post by:
DB2 8.2.3 is there a sql equivalent to get the information provided by db2 list node directory db2 list db directory. thanks.
3
4302
by: Rich | last post by:
The procedure below checks if a character entered into a cell of a datagridview is contained in a string array of valid characters for this particular cell. It seems kludgy. I am asking what the best practice would be. I was thinking I could use an arrayList which has the "contains" property and do this: If not arr.Contains(s1) then --- don't continue but my list of codes might be about 50 char combinations. So I was thinking a...
1
2844
by: htperth | last post by:
Hi all, Note that I'm new to LDAP and Active Directory and am writing an application that retrieves a simple phone list for all the users in our domain. So far I have the following console app code that seems to work. It queries Active Directory for a phone list and correctly retrieves the names (cn) from the OU. Though I have asked for properties like telephoneNumber, homeNumber, mobile, ipphone, facsimileTelephoneNumber...the properties are...
1
3976
by: htperth | last post by:
Hi all, Note that I'm new to LDAP and Active Directory and am writing an application that retrieves a simple phone list for all the users in our domain. So far I have the following console app code that seems to work. It queries Active Directory for a phone list and correctly retrieves the names (cn) from the OU. Though I have asked for properties like telephoneNumber, homeNumber, mobile, ipphone, facsimileTelephoneNumber...the properties are...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.