LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-03-2015, 02:43 AM   #1
newuser85
LQ Newbie
 
Registered: Aug 2015
Posts: 15

Rep: Reputation: Disabled
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

Last edited by newuser85; 11-03-2015 at 02:48 AM.
 
Old 11-03-2015, 02:54 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
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?
 
Old 11-03-2015, 03:01 AM   #3
newuser85
LQ Newbie
 
Registered: Aug 2015
Posts: 15

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-03-2015, 03:22 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by newuser85 View Post
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
That's not what I mean. This structure is fine.

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?
 
Old 11-03-2015, 03:39 AM   #5
newuser85
LQ Newbie
 
Registered: Aug 2015
Posts: 15

Original Poster
Rep: Reputation: Disabled
Hi,


When I tried to echo pwd got the below


+ read FName
++ pwd
+ echo none\d\lsenv\law\bin
/+ '[' '!' -d archive ']'

thanks
 
Old 11-03-2015, 06:23 AM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by newuser85 View Post
Hi,


When I tried to echo pwd got the below


+ read FName
++ pwd
+ echo none\d\lsenv\law\bin
/+ '[' '!' -d archive ']'

thanks
Not "echo pwd", just "pwd".
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Copy directory - exclude files/folders dirtyrobinson Linux - General 3 12-12-2013 05:23 AM
[SOLVED] Rsync exclude a directory with all subdirectories and files Slackovado Slackware 1 12-26-2010 11:40 PM
Process all files in directory cgcamal Programming 5 01-23-2009 12:20 PM
Best way to process a group of files (whole directory, wildcards etc.) garrettderner Linux - Newbie 11 07-31-2008 08:15 PM
PHP: List files in directory, exclude backups kenneho Programming 2 12-30-2005 04:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration