בירור | מיון קבצים מרובים לפי שמות
-
תיקייה שיש בה מאות קבצים
יש לי קובץ אקסל עם שמות הקבצים ממוינים לפי נושאים
אני רוצה למיין את הקבצים לפי הסדר באקסל.
אפשר להעתיק 30 שמות של קבצים, לבחור אותם בלחיצת כפתור, ולהעתיק אותם לתיקיה נפרדת, וכן הלאה לשאר הקבצים?ביקשתי מגמיני שיכתוב לי קוד עבור זה
זה מה שכתב
זה תקין?
יש משהו אחר טוב יותר?===group```# נתיב לתיקיה הראשית שמכילה את הקבצים $sourceFolder = "C:\Your\Source\Folder" # נתיב לקובץ הטקסט שמכיל את רשימת הנושאים והקבצים $topicFile = "C:\Your\Topic\File.txt" # קריאה של רשימת הנושאים והקבצים מהקובץ $topics = Get-Content $topicFile # יצירת מילון לאחסון מספר הקבצים בכל נושא $fileCounts = @{} foreach ($line in $topics) { # פיצול השורה לנושא ושמות קבצים $topic, $fileNames = $line -split ':', 2 # יצירת תיקייה חדשה עבור הנושא אם היא לא קיימת $topicFolder = Join-Path $sourceFolder $topic if (!(Test-Path $topicFolder)) { New-Item -ItemType Directory -Path $topicFolder } # ספירת הקבצים והעברתם לתיקייה $fileCount = 0 foreach ($fileName in $fileNames -split ',') { $filePath = Join-Path $sourceFolder $fileName.Trim() if (Test-Path $filePath) { Move-Item $filePath $topicFolder $fileCount++ } } # הוספת מספר הקבצים למילון $fileCounts[$topic] = $fileCount } # הדפסת מספר הקבצים בכל נושא foreach ($topic in $fileCounts.Keys) { Write-Host "Topic '$topic' has $($fileCounts[$topic]) files." } ```kotlin
===
-
אני קודם רוצה לבדוק שהבנתי נכון,
אתה רוצה להכניס כל X קבצים לתיקייה במקום המצב הנוכחי שכולם בתיקייה אחת.איך נראה הקובץ אקסל?
@נעזר1000 יש לי תיקייה עם 300 קבצים
אני רוצה להוציא אותם מהתיקייה הנוכחית (או לחלק אותם לתתי תיקיות באותה תיקיה)
ולחלק אותם ל3 תיקיות לפי נושאים.
בקובץ אקסל יש לי עמודה אחת עם שמות כל הקבצים כפי שהם מופיעית בתיקייה הנוכחית
בעמודה ליד מופיע לאיזה תיקייה זה אמור להיות.
אני יכול לסנן את הקבצים שאמורים להגיע לתיקייה מס' 1
להעתיק את כל שמות הקבצים ולהדביק אותם באיזה שורת קוד שתוציא אותם מהתיקייה הנוכחית ולהעביר לתיקיה מס' 1.
וכן הלאה לשאר הקבצים. -
@נעזר1000 יש לי תיקייה עם 300 קבצים
אני רוצה להוציא אותם מהתיקייה הנוכחית (או לחלק אותם לתתי תיקיות באותה תיקיה)
ולחלק אותם ל3 תיקיות לפי נושאים.
בקובץ אקסל יש לי עמודה אחת עם שמות כל הקבצים כפי שהם מופיעית בתיקייה הנוכחית
בעמודה ליד מופיע לאיזה תיקייה זה אמור להיות.
אני יכול לסנן את הקבצים שאמורים להגיע לתיקייה מס' 1
להעתיק את כל שמות הקבצים ולהדביק אותם באיזה שורת קוד שתוציא אותם מהתיקייה הנוכחית ולהעביר לתיקיה מס' 1.
וכן הלאה לשאר הקבצים. -
@נעזר1000 יש לי תיקייה עם 300 קבצים
אני רוצה להוציא אותם מהתיקייה הנוכחית (או לחלק אותם לתתי תיקיות באותה תיקיה)
ולחלק אותם ל3 תיקיות לפי נושאים.
בקובץ אקסל יש לי עמודה אחת עם שמות כל הקבצים כפי שהם מופיעית בתיקייה הנוכחית
בעמודה ליד מופיע לאיזה תיקייה זה אמור להיות.
אני יכול לסנן את הקבצים שאמורים להגיע לתיקייה מס' 1
להעתיק את כל שמות הקבצים ולהדביק אותם באיזה שורת קוד שתוציא אותם מהתיקייה הנוכחית ולהעביר לתיקיה מס' 1.
וכן הלאה לשאר הקבצים. -
@קוקר מצורף קוד פייתון שעושה את זה,
והנה קובץ מקומפל, רק שים לב שעל קובץ האקסל והקבצים להיות באותה תיקייה של התוכנה, וקובץ האקסל צריך להיות בשם "שמות הקבצים", ולהיות עם שמות העמודות בשורה הראשונה "שם הקובץ" ו"התיקיה להעברה".
https://send.magicode.me/send-file/file/bfd1facfd91b75f232f7a1990bfc2adb2fceebed/view
# Developed by abaye © # https://ko-fi.com/abaye # email: cs@abaye.co # The source of the icon image is the site icons8.com import os import pandas as pd import shutil import sys def get_script_directory(): if getattr(sys, 'frozen', False): # Running as a compiled executable (PyInstaller) return os.path.dirname(sys.executable) else: # Running as a script return os.path.dirname(os.path.abspath(__file__)) script_directory = get_script_directory() files_directory = script_directory excel_file_path = os.path.join(files_directory, 'שמות הקבצים.xlsx') try: # טען את הנתונים מקובץ האקסל, תוך דילוג על השורה הראשונה עם הכותרות df = pd.read_excel(excel_file_path) except FileNotFoundError: print(f"שגיאה: קובץ האקסל '{excel_file_path}' לא נמצא.") exit(1) except Exception as e: print(f"שגיאה: לא ניתן לטעון את קובץ האקסל. שגיאה: {e}") exit(1) #df = pd.read_excel(excel_file_path) for index, row in df.iterrows(): file_name = row['שם הקובץ'] folder_name = row['התיקיה להעברה'] file_path = os.path.join(files_directory, file_name) destination_folder = os.path.join(files_directory, folder_name) if not os.path.exists(destination_folder): os.makedirs(destination_folder) destination_path = os.path.join(destination_folder, file_name) try: shutil.copy(file_path, destination_path) print(f"הקובץ '{file_name}' הועתק לתיקייה '{folder_name}' בהצלחה.") except FileNotFoundError: print(f"שגיאה: הקובץ '{file_name}' לא נמצא בתיקייה הראשית.") except Exception as e: print(f"שגיאה: לא ניתן להעתיק את הקובץ '{file_name}'. שגיאה: {e}") print("הפעולה הסתיימה!")
-
@קוקר מצורף קוד פייתון שעושה את זה,
והנה קובץ מקומפל, רק שים לב שעל קובץ האקסל והקבצים להיות באותה תיקייה של התוכנה, וקובץ האקסל צריך להיות בשם "שמות הקבצים", ולהיות עם שמות העמודות בשורה הראשונה "שם הקובץ" ו"התיקיה להעברה".
https://send.magicode.me/send-file/file/bfd1facfd91b75f232f7a1990bfc2adb2fceebed/view
# Developed by abaye © # https://ko-fi.com/abaye # email: cs@abaye.co # The source of the icon image is the site icons8.com import os import pandas as pd import shutil import sys def get_script_directory(): if getattr(sys, 'frozen', False): # Running as a compiled executable (PyInstaller) return os.path.dirname(sys.executable) else: # Running as a script return os.path.dirname(os.path.abspath(__file__)) script_directory = get_script_directory() files_directory = script_directory excel_file_path = os.path.join(files_directory, 'שמות הקבצים.xlsx') try: # טען את הנתונים מקובץ האקסל, תוך דילוג על השורה הראשונה עם הכותרות df = pd.read_excel(excel_file_path) except FileNotFoundError: print(f"שגיאה: קובץ האקסל '{excel_file_path}' לא נמצא.") exit(1) except Exception as e: print(f"שגיאה: לא ניתן לטעון את קובץ האקסל. שגיאה: {e}") exit(1) #df = pd.read_excel(excel_file_path) for index, row in df.iterrows(): file_name = row['שם הקובץ'] folder_name = row['התיקיה להעברה'] file_path = os.path.join(files_directory, file_name) destination_folder = os.path.join(files_directory, folder_name) if not os.path.exists(destination_folder): os.makedirs(destination_folder) destination_path = os.path.join(destination_folder, file_name) try: shutil.copy(file_path, destination_path) print(f"הקובץ '{file_name}' הועתק לתיקייה '{folder_name}' בהצלחה.") except FileNotFoundError: print(f"שגיאה: הקובץ '{file_name}' לא נמצא בתיקייה הראשית.") except Exception as e: print(f"שגיאה: לא ניתן להעתיק את הקובץ '{file_name}'. שגיאה: {e}") print("הפעולה הסתיימה!")
@אביי
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Home\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1255.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9f in position 647: character maps to <undefined> -
@אביי
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Home\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1255.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9f in position 647: character maps to <undefined>@אלף-שין כתב בבירור | מיון קבצים מרובים לפי שמות:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Home\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1255.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9f in position 647: character maps to <undefined>השתמשת בקובץ האקסל שהבאתי במג'יק?
-
@אלף-שין כתב בבירור | מיון קבצים מרובים לפי שמות:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Home\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1255.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9f in position 647: character maps to <undefined>השתמשת בקובץ האקסל שהבאתי במג'יק?
-
@קוקר מצורף קוד פייתון שעושה את זה,
והנה קובץ מקומפל, רק שים לב שעל קובץ האקסל והקבצים להיות באותה תיקייה של התוכנה, וקובץ האקסל צריך להיות בשם "שמות הקבצים", ולהיות עם שמות העמודות בשורה הראשונה "שם הקובץ" ו"התיקיה להעברה".
https://send.magicode.me/send-file/file/bfd1facfd91b75f232f7a1990bfc2adb2fceebed/view
# Developed by abaye © # https://ko-fi.com/abaye # email: cs@abaye.co # The source of the icon image is the site icons8.com import os import pandas as pd import shutil import sys def get_script_directory(): if getattr(sys, 'frozen', False): # Running as a compiled executable (PyInstaller) return os.path.dirname(sys.executable) else: # Running as a script return os.path.dirname(os.path.abspath(__file__)) script_directory = get_script_directory() files_directory = script_directory excel_file_path = os.path.join(files_directory, 'שמות הקבצים.xlsx') try: # טען את הנתונים מקובץ האקסל, תוך דילוג על השורה הראשונה עם הכותרות df = pd.read_excel(excel_file_path) except FileNotFoundError: print(f"שגיאה: קובץ האקסל '{excel_file_path}' לא נמצא.") exit(1) except Exception as e: print(f"שגיאה: לא ניתן לטעון את קובץ האקסל. שגיאה: {e}") exit(1) #df = pd.read_excel(excel_file_path) for index, row in df.iterrows(): file_name = row['שם הקובץ'] folder_name = row['התיקיה להעברה'] file_path = os.path.join(files_directory, file_name) destination_folder = os.path.join(files_directory, folder_name) if not os.path.exists(destination_folder): os.makedirs(destination_folder) destination_path = os.path.join(destination_folder, file_name) try: shutil.copy(file_path, destination_path) print(f"הקובץ '{file_name}' הועתק לתיקייה '{folder_name}' בהצלחה.") except FileNotFoundError: print(f"שגיאה: הקובץ '{file_name}' לא נמצא בתיקייה הראשית.") except Exception as e: print(f"שגיאה: לא ניתן להעתיק את הקובץ '{file_name}'. שגיאה: {e}") print("הפעולה הסתיימה!")
-
@אלף-שין כתב בבירור | מיון קבצים מרובים לפי שמות:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Home\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1255.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9f in position 647: character maps to <undefined>השתמשת בקובץ האקסל שהבאתי במג'יק?
-
@אביי כתב בבירור | מיון קבצים מרובים לפי שמות:
השתמשת בקובץ האקסל שהבאתי במג'יק?
לא, הרצתי את הסקריפט ישירות,
[אם כי אציין שבחדר מחשבים תמיד יש בעיה עם תוויים בעברית בפייתון]
אחכה שיפתח. -
@אלף-שין תנסה להשתמש בקובץ אקסל הזה, שמצורף בzip שהעליתי למג'יק
שמות הקבצים.xlsx -
@אלף-שין תנסה להשתמש בקובץ אקסל הזה, שמצורף בzip שהעליתי למג'יק
שמות הקבצים.xlsxTraceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1255.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'charmap' codec can't decode byte 0x9c in position 727: character maps to <undefined> >>>
-
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1255.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'charmap' codec can't decode byte 0x9c in position 727: character maps to <undefined> >>>