-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b0f5ca
commit 115a9d9
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
|
||
def traverse_files(directory): | ||
for root, dirs, files in os.walk(directory): | ||
for file_name in files: | ||
if file_name.endswith(".sh"): # Only operate on files with .sh extension | ||
file_path = os.path.join(root, file_name) | ||
with open(file_path, "r") as file: | ||
file_content = file.read() | ||
|
||
# Replace strings | ||
replacement = "/usr/bin/env " | ||
file_content = file_content.replace("/usr/bin/env ", "<placeholder>") | ||
file_content = file_content.replace("/usr/bin/", replacement) | ||
file_content = file_content.replace("<placeholder>", "/usr/bin/env ") | ||
|
||
with open(file_path, "w") as file: | ||
file.write(file_content) | ||
|
||
print("File", file_name, "has been updated!") | ||
|
||
print("Batch replace completed!") | ||
|
||
# Get the current directory | ||
current_dir = os.getcwd() | ||
|
||
# Traverse files in the current directory | ||
traverse_files(current_dir) |