עזרה | מספור קבצים בתיקיה
-
יש לי מספר רב של קבצים בתיקיה.
לדוגמא
rava.txt
abye.txt
shmuel.txt
rvina.txt
וכן על זה הדרך.
אני רוצה, באמצעות קובץ bat, לשנות את כל השמות ל
amora1.txt
amora2.txt
amora3.txt
amora4.txt
צריך דווקא דרך bat.
עוד דבר-לא תסייע לי פקודה דווקא לשמות הקבצים שלמעלה-כי אני צריך את זה באופן כללי.
ניסיתיren *.txt amora.txt
אבל אז אחרי הקובץ הראשון הוא אומר שקיים כבר קובץ בשם זה.
ניסיתי גםren *.txt amora*.txt
אבל אז הוא עושה ככה
amorarava.txt
amoraabye.txt
amorashmuel.txt
amorarvina.txtתודה רבה!
מניח שהשאלה נשאלה כבר בעבר, אבל לא מצאתי בחיפוש. -
יש לי מספר רב של קבצים בתיקיה.
לדוגמא
rava.txt
abye.txt
shmuel.txt
rvina.txt
וכן על זה הדרך.
אני רוצה, באמצעות קובץ bat, לשנות את כל השמות ל
amora1.txt
amora2.txt
amora3.txt
amora4.txt
צריך דווקא דרך bat.
עוד דבר-לא תסייע לי פקודה דווקא לשמות הקבצים שלמעלה-כי אני צריך את זה באופן כללי.
ניסיתיren *.txt amora.txt
אבל אז אחרי הקובץ הראשון הוא אומר שקיים כבר קובץ בשם זה.
ניסיתי גםren *.txt amora*.txt
אבל אז הוא עושה ככה
amorarava.txt
amoraabye.txt
amorashmuel.txt
amorarvina.txtתודה רבה!
מניח שהשאלה נשאלה כבר בעבר, אבל לא מצאתי בחיפוש.@מישהו12 משנה לך שיהיה
amora1.txt
amora2.txt
amora3.txt
amora4.txtאו שגם זה טוב?
amora(1).txt
amora(2).txt
amora(3).txt
amora(4).txt
כי אם בוחרים הרבה קבצים מאותו סוג קובץ ועושים שנה שם ורושמים שם לקובץ
זה הופך את כל הקבצים לאותו שם ורק מוסיף מספרים בסוגריים בסדר עולה -
ניסיתי עוד פקודה
for /L %%a in (1,1,5) do ren *.txt %%a.txt
לא הצלחתי להבין את הבעיה עד הסוף.
הנה הפלטC:\Users\----\Desktop\apps - עותק\תיקיה חדשה>ren *.txt 1.txt A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. C:\Users\----\Desktop\apps - עותק\תיקיה חדשה>ren *.txt 2.txt A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. C:\Users\----\Desktop\apps - עותק\תיקיה חדשה>ren *.txt 3.txt A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. C:\Users\----\Desktop\apps - עותק\תיקיה חדשה>ren *.txt 4.txt A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. C:\Users\----\Desktop\apps - עותק\תיקיה חדשה>ren *.txt 5.txt A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found. A duplicate file name exists, or the file cannot be found.
עריכה: הבנתי מה הייתה השגיאה.
בפעם הראשונה שהלולאה רצה (והערך של a הוא 1) הוא משנה את כל הtxt ל1.txt, כי הרי כתוב לו *.txt.
ואז הוא נתקע אחרי הקובץ הראשון, כי כבר קיים קובץ כזה.
אז הוא עובר לשלב הבא בלולאה, ושוב אותו דבר, וכן הלאה.
יש למישהו רעיון? -
תכל'ס... עשיתי פיתרון אולטרא ערבי והבעיה היא שהוא מציק כי אם מדובר ביותר מכמה קבצים זה הרבה הזנת נתונים...
הקוד לקוח מכאן:@ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION rem Load the list of new filenames set i=0 for /F "delims=" %%a in (names.txt) do ( set /A i+=1 set "newname[!i!]=%%a" ) rem Do the rename: set i=0 for /F "delims=" %%a in ('dir /b /o:n *.txt') do ( set /A i+=1 for %%i in (!i!) do ren "%%a" "!newname[%%i]!" )
ותוכן הקובץ names.txt הוא
1.txt 2.txt 3.txt 4.txt 5.txt
הבעיה היא שבשביל זה, בכל מקרה אני צריך לשים לפי מספר הקבצים שבאותו מקרה...
יש למישהו רעיון יותר טוב?
@משחזר-מידע -
תכל'ס... עשיתי פיתרון אולטרא ערבי והבעיה היא שהוא מציק כי אם מדובר ביותר מכמה קבצים זה הרבה הזנת נתונים...
הקוד לקוח מכאן:@ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION rem Load the list of new filenames set i=0 for /F "delims=" %%a in (names.txt) do ( set /A i+=1 set "newname[!i!]=%%a" ) rem Do the rename: set i=0 for /F "delims=" %%a in ('dir /b /o:n *.txt') do ( set /A i+=1 for %%i in (!i!) do ren "%%a" "!newname[%%i]!" )
ותוכן הקובץ names.txt הוא
1.txt 2.txt 3.txt 4.txt 5.txt
הבעיה היא שבשביל זה, בכל מקרה אני צריך לשים לפי מספר הקבצים שבאותו מקרה...
יש למישהו רעיון יותר טוב?
@משחזר-מידע@מישהו12 מה אומר ?
set /a Index=1 setlocal enabledelayedexpansion for /r %%i in (*.txt) do ( rename "%%i" amora"!Index!.txt" set /a Index+=1 )
-
@מישהו12 מה אומר ?
set /a Index=1 setlocal enabledelayedexpansion for /r %%i in (*.txt) do ( rename "%%i" amora"!Index!.txt" set /a Index+=1 )
-
@מישהו12 מה אומר ?
set /a Index=1 setlocal enabledelayedexpansion for /r %%i in (*.txt) do ( rename "%%i" amora"!Index!.txt" set /a Index+=1 )
-
יש לי מספר רב של קבצים בתיקיה.
לדוגמא
rava.txt
abye.txt
shmuel.txt
rvina.txt
וכן על זה הדרך.
אני רוצה, באמצעות קובץ bat, לשנות את כל השמות ל
amora1.txt
amora2.txt
amora3.txt
amora4.txt
צריך דווקא דרך bat.
עוד דבר-לא תסייע לי פקודה דווקא לשמות הקבצים שלמעלה-כי אני צריך את זה באופן כללי.
ניסיתיren *.txt amora.txt
אבל אז אחרי הקובץ הראשון הוא אומר שקיים כבר קובץ בשם זה.
ניסיתי גםren *.txt amora*.txt
אבל אז הוא עושה ככה
amorarava.txt
amoraabye.txt
amorashmuel.txt
amorarvina.txtתודה רבה!
מניח שהשאלה נשאלה כבר בעבר, אבל לא מצאתי בחיפוש.