Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Nebo task#38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dkhomia wants to merge2 commits intorealpython:master
base:master
Choose a base branch
Loading
fromdkhomia:NEbo-task
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletionsscripts/04_rename_with_slice.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
import os
import glob
import sys

os.chdir("/Users/mikeherman/repos/bugs/se-platform/se/core/permissions")
for file in glob.glob("*.json"):
file_name = os.path.splitext(file)[0]
extension = os.path.splitext(file)[1]
new_file_name = file_name[:-6] + extension
if len(sys.argv) != 4:
print("Incorrect usage, plz provide arguments like in an example: python script_name.py <folder_path> <file_type> <slicing>")
sys.exit(1)

folder_path = os.path.join(sys.argv[1])
file_type = sys.argv[2]
slicing = int(sys.argv[3])

os.chdir(folder_path)

for file in glob.glob(f"*.{file_type}"):
file_name, extension = os.path.splitext(file)
new_file_name = f"{file_name[:-slicing]}{extension}"
try:
os.rename(file, new_file_name)
except OSError ase:
print(e)
except OSError aserr:
print(err)
else:
print("Renamed {} to {}".format(file, new_file_name))
print(f"Renamed {file} to {new_file_name}")

[8]ページ先頭

©2009-2025 Movatter.jp