How to exclude a sub directory within a directory and process the files alone
Hi All,
Part of my Script I want to process only the files inside a directory. I don't want the sub-directory to get processed. Please find the code snippet below. cat $FtpList | \ while read FName do if [ ! -d $FName ] then ExportFileName=$FName ExportFile=${LocalDir}\\${FName} RemoteFileName=$FName callSub $subCall transferLFtpFileLocal $RemoteDir $RemoteFileName $LcdDir $ExportFileName $FtpDebug if [ $rc -ne 0 ] then echo "FTP ERROR Log:" cat $FtpDebug echo "ERROR: LFTP command failed." scriptExit "0" "transferLFtpFileLocal" else mv "${LocalDir}\\$FName" "${LocalArchDir}\\${FName}-${DATE}${TIME}" chmod 666 "${LocalArchDir}\\${FName}-${DATE}${TIME}" fi else echo "skipping directory: $FName" fi done ******************************************************************** O/P + '[' '!' -d archive ']' + ExportFileName=archive + ExportFile='D:\lsenv\law\lsapps\work\AMEXREMIT\archive' + RemoteFileName=archive + callSub createRndFile + subname=callSub + subList=createRndFile Here archive is a sub-directory. So I want to skip it but its not. Instead archive gets assigned to the ExportFile. ********************************************************************* I tried -f but still am not able to get what I want + read FName + '[' -f archive ']' + echo 'skipping directory: archive' + read FName + '[' -f VHA.USREMIT-0001-20151102163133 ']' + echo 'skipping directory: VHA.USREMIT-0001-20151102163133' + read FName I want VHA.USREMIT-0001-20151102163133 to be processed, but its also getting recognized as a directory. ********************************************************************** Please advise. Thanks |
The -d test succeds if archive exists and is a directory. Since the name "archive" is a relative pathname, your script will only work if archive exists in the current directory of your script. Could this be your problem?
|
Hi,
thanks for your reply. Fyi I am running the script on windows environment using Cygwin. Script Path : D:\lsenv\law\bin Archive directory path : D:\lsenv\law\lsapps\work\AMEXREMIT\archive You mean the above directory structure wont work for the script. Correct me if I am wrong. Also let me know any work around for the issue. thanks |
Quote:
Any Linux process, and also Windows if I am not wrong, has a current directory at any time. This directory can be changed with the cd command on both OS's. It can be printed with pwd in Linux and also Cygwin (don't know about Windows). What is the current directory of your script when it makes the -d test? |
Hi,
When I tried to echo pwd got the below + read FName ++ pwd + echo none\d\lsenv\law\bin /+ '[' '!' -d archive ']' thanks |
Quote:
I do wonder what command you used to get this output; echo $(pwd) perhaps? In this case, the current directory of the script is not d:/.../AMEXREMIT, and your script will therefore not work. Since I know neither context nor environment, I can't give you good tips what to do to fix this. However, try including a cd d:/.../AMEXREMIT before the read command or near the beginning of the script. |
All times are GMT -5. The time now is 02:24 PM. |