您好,我需要根据文件名创建一个文件夹,并在此文件夹中创建另一个,然后将文件移至第二个文件夹
示例:
my_file.jpg
创建文件夹my_file
创建文件夹图片
将my_file.jpg移至图片
我有此脚本,但它仅适用于Windows,现在我正在使用Linux
for %%A in (*.jpg) do mkdir "%%~nA/picture" & move "%%A" "%%~nA/picture"
pause
抱歉,如果我不太准确,但英语不是我的母语。
#!/usr/bin/env bash
# Enable bash built-in extglob to ease file matching.
shopt -s extglob
# To deal with the case where nothing matches. (courtesy of mklement0)
shopt -s nullglob
# A pattern to match files with specific file extensions.
# Example for matching additional file types.
#match="*+(jpg|.png|.gif)"
match="*+(.jpg)"
# By default use the current working directory.
src="${1:-.}"
dest="${2:-/root/Desktop/My_pictures/}"
# Pass an argument to this script to name the subdirectory
# something other than picture.
subdirectory="${3:-picture}"
# For each file matched
for file in "${src}"/$match
do
# make a directory with the same name without file extension
# and a subdirectory.
targetdir="${dest}/$(basename "${file%.*}")/${subdirectory}"
# Remove echo command after the script outputs fit your use case.
echo mkdir -p "${targetdir}"
# Move the file to the subdirectory.
echo mv "$file" "${targetdir}"
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句