Jak zmienić nazwy plików w podkatalogach?
Czy istnieje możliwość zmiany nazw plików w podkatalogach?
Na przykład:
Zmień nazwę *.html
na *.htm
w folderze, który ma katalogi i podkatalogi.
10 answers
Wiersz polecenia systemu Windows: (jeśli wewnątrz pliku wsadowego, Zmień %x Na %%x)
for /r %x in (*.html) do ren "%x" *.htm
Działa to również przy zmianie nazwy środka plików
for /r %x in (website*.html) do ren "%x" site*.htm
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-13 20:20:08
find . -regex ".*html$" | while read line;
do
A=`basename ${line} | sed 's/html$/htm/g'`;
B=`dirname ${line}`;
mv ${line} "${B}/${A}";
done
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-29 05:15:11
W Pythonie
import os
target_dir = "."
for path, dirs, files in os.walk(target_dir):
for file in files:
filename, ext = os.path.splitext(file)
new_file = filename + ".htm"
if ext == '.html':
old_filepath = os.path.join(path, file)
new_filepath = os.path.join(path, new_file)
os.rename(old_filepath, new_filepath)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-29 05:17:27
W Bash możesz wykonać następujące czynności:
for x in $(find . -name \*.html); do
mv $x $(echo "$x" | sed 's/\.html$/.htm/')
done
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-29 05:28:20
Jestem pewien, że jest bardziej elegancki sposób, ale oto pierwsza rzecz, która pojawiła się w mojej głowie:
for f in $(find . -type f -name '*.html'); do
mv $f $(echo "$f" | sed 's/html$/htm/')
done
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-29 05:27:18
In bash use command rename :)
rename 's/\.htm$/.html/' *.htm
# or
find . -name '*.txt' -print0 | xargs -0 rename 's/.txt$/.xml/'
#Obs1: Above I use regex \. --> literal '.' and $ --> end of line
#Obs2: Use find -maxdepht 'value' for determine how recursive is
#Obs3: Use -print0 to avoid 'names spaces asdfa' crash!
Jeśli masz forfiles (chodzi o Windows XP i 2003 i nowsze rzeczy myślę) możesz uruchomić:
forfiles /S /M *.HTM /C "cmd /c ren @file *.HTML"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2021-01-23 20:51:14
W Linuksie możesz użyć polecenia 'rename' do zmiany nazw plików w partiach.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-29 06:11:29
AWK na Linuksie. Dla pierwszego katalogu jest to twoja odpowiedź... Ekstrapoluj rekurencyjnie wywołując awk na dir_path, być może pisząc inny awk, który zapisuje dokładnie ten awk poniżej... i tak dalej.
ls dir_path/. | awk -F"." '{print "mv file_name/"$0" dir_path/"$1".new_extension"}' |csh
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-29 07:07:20
Na Unixie możesz użyć rnm :
rnm -rs '/\.html$/.htm/' -fo -dp -1 *
Lub
rnm -ns '/n/.htm' -ss '\.html$' -fo -dp -1 *
Wyjaśnienie:
-
-ns
: name string (nowa nazwa). {[3] } jest regułą ciągu nazw, która rozszerza się do nazwy pliku bez rozszerzenia. -
-ss
: search string (regex). Wyszukuje pliki z dopasowaniem. -
-rs
: zastąp łańcuch postaci/search_regex/replace_part/modifier
-
-fo
: tryb Tylko pliku -
-dp
: głębokość katalogu (-1 oznacza nieograniczony).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-07 07:35:25