繁体   English   中英

bash-如何检测我的文件是否在(子)文件夹中

[英]bash - How to detect if my file is in a (sub)folder

我正在尝试编写脚本以在bash中使用文件后移动文件。 我正在使用“用...打开”脚本,因此$1是文件(完整路径)

#! /bin/bash

fullpath="$1"
rootpath="/home/guillaume/Videos"
foo=${fullpath#${rootpath}}
echo "$foo"

zenity --question --title="Déplacer le fichier ?" --text="Déplacer le fichier vers le dossier VU ?"
if [ $? = 0 ]
then
    if # foo don't have a folder
    then
       mv $rootpath"$foo" /home/guillaume/Videos/VU
    elif # foo contains a folder
       # command to copy the subdirectory
    fi
fi

foo的结果可能是:

/title_subdirectory/file with_spaces or_not.ext

要么

/file with_spaces or_not.ext

如何检测文件是否在子目录中,然后移动所有子目录和文件?

我要检查文件名是否与basename名相同(不带目录的名称)

if [ `basename "$foo"` = "$foo" ] ; then
  echo root directory
else
  echo subdirectory
fi

如果根目录中的文件带有前导/则在比较之前,您可能需要这样做以除去前导/

if [ `basename "$foo"` = "${foo#/}" ] ; then
  echo root directory
else
  echo subdirectory
fi

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM