简体   繁体   English

在 python 中使用 sql 查询重命名系统文件夹

[英]Rename system folder using sql query in python

I have made a power automate flow that runs when someone submit a Microsoft form, the result will create a folder of the name of the person who filled that form (Name field is mandatory in the form) and store the files into that folder he has attached at the time of filling the form.我已经制作了一个当有人提交 Microsoft 表单时运行的自动流程,结果将创建一个以填写该表单的人的名字命名的文件夹(表单中的名称字段是必需的)并将文件存储到他拥有的那个文件夹中填写表格时附上。 Names also gets updated in the database under xyz table.名称也会在 xyz 表下的数据库中更新。 It is sure that if 10 people fill the form in a day then in database also there will be 10 rows added under Name column.可以肯定的是,如果一天有 10 个人填写表格,那么在数据库中也会在名称列下添加 10 行。

In xyz table there is one more column named surname.在 xyz 表中还有一列名为姓氏。 It also gets updated along with name column.它还会与名称列一起更新。 example below:下面的例子:

Name    Surname

David   Warner
Shane   Watson

What I want is to make a python script that check names from the database daily and change folder names to surname.我想要的是制作一个 python 脚本,每天检查数据库中的名称并将文件夹名称更改为姓氏。 Basically, the script will check if name = David then changes the folder name to Warner and if name = Shane then changes it to Watson and so on... I have no idea how to rename like this.基本上,脚本将检查 name = David 是否将文件夹名称更改为 Warner,如果 name = Shane 则将其更改为 Watson 等等......我不知道如何重命名这样。

Actually it makes your work hard when some names may be duplicated and folder names can't be.实际上,当某些名称可能重复而文件夹名称不能重复时,这会使您的工作变得困难。 I recommend you to use sth like unique primary key as auto increment and make folder for every id of users.我建议您使用诸如唯一主键之类的东西作为自动增量并为每个用户 ID 创建文件夹。 In such case you don't need to change anything.在这种情况下,您不需要更改任何内容。 It is a little bit hard to find out files but it is easy to implement.查找文件有点困难,但很容易实现。

Another way to implement sth like this is to structure folder based on Year/Month/Day of creation.另一种实现这样的方法是根据创建的年/月/日来构建文件夹。 This is organized and you can store the file path as another field in DB and easily access them.这是有组织的,您可以将文件路径存储为数据库中的另一个字段并轻松访问它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM