如何创建从 .txt 或特定文件夹中的任何文本文档搜索值的程序
我对编程比较陌生,想要创建一个可以解决我经常遇到的问题的程序。
这是我的短篇故事的背景:我在一个托管许多文件的网站上(我们谈论的是大约 500-1000 个小文件)。我当时想,“天哪!我想把所有这些东西都放在我的硬盘上,这样我就知道我可以访问它们......但我可能不会以任何方式使用它们”。我继续下载该网站上的所有 500-1000 个文件,但在查看目标文件的属性时遇到问题。假设网站上有 500 个文件,我的计算机上只有 499 个文件。只是我的运气。我想知道那个从我身边溜走的讨厌文件是什么,并专门下载该文件。我不想做的是删除所有文件,然后再次尝试从网站下载所有文件。在该网站上,没有任何迹象表明我下载了所有文件,所以我完全不知所措。我可以按 Ctrl+C 进入每个项目,然后按 Ctrl+V 进入文件管理器搜索栏,但重复 500 次会很乏味。
现在,我想做的事情:我想继续从网站获取所有文件名(我下载的文件名和驱动器中的文件名相同) ,将它们全部放入一个简单的 .txt 文档或其他内容中(该网站在我需要的文本旁边有多个不需要的文本,例如:
如果无法像这样从网站中提取文本,那么我没问题。通过复制粘贴手动输入名称)。然后我希望计算机获取文档中的这些值,然后在特定的文件夹路径中搜索它(注意:实际文件位于我要选择的根文件夹内的子文件夹中,因此程序必须能够在其中搜索根目录的多个文件夹)。然后我希望计算机知道文档中的值是否作为文件存在。如果该文件不存在,那么我希望文档中的该值/那些值显示为输出。我希望重复这个循环,直到所有值都已完成。输出应列出不存在的值。
结论:您现在可能明白我想要做什么,如果您不明白,请告诉我需要详细说明的内容。我真的不在乎这个程序是如何制作的(什么语言或软件),我只想要一些有用的东西......但我自己不知道如何创建。
感谢您的阅读,如有任何回复,我们将不胜感激!
丹万斯 P :)
I am relatively new to programming and want to create a program which can solve a problem that I frequently have.
So here's the background to my short story: I was on a website which hosted many files (We're talking about around 500-1000 small files). I was then like," Oh sweet! I want to have all these things in my hard drive so I know that I have access to them... but am probably not going to use them either way". I proceeded to download all 500-1000 files on that site, but encountered a problem when I looked at the properties of my destination file. Let's say that out of 500 on the site, my computer only had 499 files. Just my luck. I wanted to know what was that one pesky file that slipped right by me and download that file specifically. What I didn't want to do was to delete all the files and then try my luck once more in downloading all the files from the website. On the site, there was no indication of what all files I downloaded, so I was completely in the blue. I could go in Ctrl+C each item, then Ctrl+V into the file manager search bar, but that would be tedious to repeat that 500 times.
Now, what I want to do: I wanted to go ahead and take all of the file names from the website (The file name that I downloaded and the file name that was in my drive are the same), put them all in a simple .txt document or something (The website has multiple unwanted text alongside the text I need, such as:
. If this is not possible to extract the text from the site like this, then I am ok with manually entering the names via copy paste). Then I want the computer to take these values in the document and then search for it in a specific folder path (Note: the actual files are in subfolders within the root folder I want to choose, so the program has to be able to search within multiple folders of the root). Then I want the computer to know if the value in the document, is present as a file. If the file doesn't exist, then I want that value/those values in the document to be displayed as the output. I want this cycle to repeat until all the values have been gone through. The output should list the values that were not present.
Conclusion: You probably now get at what I am trying to do, if you don't, tell me what I need to elaborate on. I really don't care how this program is made (what language or software), I just want something that works... but myself don't know how to create.
Thanks for reading and any response is appreciated!
Dhanwanth P :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想探索,这里有一个 Python 解决方案...
与您所描述的类似,网站中的所有文件都列在 Excel 文件“website_files.xlsx”中
所有文件都保存在“downloaded_wav”文件夹中。无论文件保存在根目录还是子文件夹中,该脚本都将起作用。
然后我运行下面的 Python 脚本来查找丢失的文件:
输出:
Here's a solution in Python in case you would like to explore...
Similar to what you described, all files from the website are listed in an Excel file 'website_files.xlsx'
And all files are saved in a folder 'downloaded_wav'. The script will work regardless the files are saved in the root directory or sub-folders.
Then I run below Python script to look for the missing file:
Output:
不用担心;我自己用Excel找到了一个解决方案(天哪,它太强大了!)。
基本上,我从网站复制并粘贴了我的值,然后使用过滤器仅显示
.wav
的值。然后我使用文件夹中的 Power Query 来获取文件夹中所有文件名称的列表。最后,我继续使用公式对两者进行了比较:如果您需要更多详细说明,我很乐意提供帮助,只需回复即可。可能有一种更简单的方法,但我个人喜欢这种直接性。您只需要 Microsoft Excel!
编辑:
对我来说,我使用了这两个视频来介绍 power query 和 countif 函数:
如何在 Excel 中获取文件夹中的文件名列表(无需 VBA):https://www.youtube.com/watch?v=OSCPVBWOqwc
如何比较两个 Excel 工作表(以及找出差异):https://www.youtube.com/watch?v=8Ou_wfzcKKk
就我而言,我的工作表如下所示:
No worries; I found a solution by myself using Excel (God, it's powerful!).
Basically, I copied and pasted my values from the website, then used a filter to show the values only with
.wav
. Then I used a Power Query from the folder to get me a list of all names of files in a folder. Finally, I went ahead and compared the two using a formula:If you need more elaboration, I'd be happy to help, just reply to this. There might be an easier way, but I personally liked the straight-forwardness of this. You only need Microsoft excel!
EDIT:
For me, I used these two videos which go over the power query and countif function:
How to Get the List of File Names in a Folder in Excel (without VBA): https://www.youtube.com/watch?v=OSCPVBWOqwc
How to Compare Two Excel Sheets (and find the differences): https://www.youtube.com/watch?v=8Ou_wfzcKKk
In my case, I made my sheet look like this: