简体   繁体   English

我需要更新多个文件中的一行,这些文件位于不同的文件夹中,并且都统一在一个文件夹中

[英]I need to update one line in multiple files which are in different folders and all united in one folder

I need to update(Delete one line and add one more line in the same place) one line in multiple files which are in different folders and all united in one folder.My folder structure is as below我需要更新(删除一行并在同一位置再添加一行)在不同文件夹中的多个文件中的一行,并且所有文件都在一个文件夹中。我的文件夹结构如下

Scripts脚本

Component1 (Many components) moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy (Many modules) Component1 (Many components) moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy (Many modules)

Component2 moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy Component2 moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy

文件夹结构

I have looked many sed commands but as I understand it is changing in one file not in all.我查看了许多 sed 命令,但据我所知,它不是在一个文件中更改。 Can someone help me with editing all files together.有人可以帮我一起编辑所有文件吗?

I don't have any code specifically for this, but you could have another python script that opens each file in the folders, and checks specifically for the line of code that you want to change, after that you could have it either alert you of the line location or change it manually... The code might look something like this.我没有专门用于此的任何代码,但是您可以使用另一个 python 脚本打开文件夹中的每个文件,并专门检查要更改的代码行,然后您可以让它提醒您行位置或手动更改它...代码可能看起来像这样。

   FILE_LIST = []

   REPEAT (AMOUNT OF FILES)
        OPEN(FILE) AS X
        FILE_LIST APPEND X

   REPEAT (RANGE(FILE_LIST))
        IF (LINE YOU WANT TO CHANGE) IN FILE_LIST[FILE] THEN
              ALERT
        ELSE 
              CONTINUE
for  r, d, f in os.walk(path):
    for file in f:
        if file.endswith('.grooviy'):
            update_one_line_in(os.join(r, file))

暂无
暂无

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

相关问题 Python:将文件从不同位置的多个文件夹移动到一个文件夹中 - Python: Move files from multiple folders in different locations into one folder 我需要将所有.xlsx文件保存在一个文件夹中,并保存到另一个文件夹中 - I need to save all .xlsx files in one folder, into another folder 将所有文件从一个文件夹移动到多个文件夹并通过添加后缀重命名它们 - Moving all files from one folder to multiple folders and renaming them by adding suffix 将文件夹目录中的所有.csv文件复制到python中的一个文件夹 - Copy all .csv files in a directory of folders to one folder in python 如何使用python将多个文件夹中的多个文件复制到一个文件夹中? - How to copy multiple files from multiple folders into one folder using python? 我有不同的zip文件,每个文件包含一个csv文件。 如何解压缩每个文件夹,并将所有csv文件保存在一个文件夹中 - I have different zip files that contain one csv file each. how do I unzip each folder, and save all the csv files in one folder 如何根据文件名将一个文件夹中的多个文件分成不同的文件夹? - How can I separate many files from one folder into separate folders based on the name of the files? 如何使用字典将文件从一个文件夹复制到多个其他文件夹 - How to copy files from one folder to multiple other folders using a dictionary Append csv 将多个文件夹中的文件合并到一个 dataframe - Append csv files in multiple folders into one dataframe 如何将多个文件夹中的相似命名文件合并为每个文件名的一个文件夹 - How to combine similar named files from multiple folders into one folder for each file name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM