how to test filename is file or directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to test filename is file or directory
# 1  
Old 11-01-2006
Java how to test filename is file or directory

hi all
plz let me how to test output of "tail -1 filelist.lst" is file or directory.
regards
-Bali Reddy
# 2  
Old 11-01-2006
Code:
file=$(tail -f filelist.lst)
[ -d $file ] && echo "$file is a directory"
[ -f $file ] && echo "$file is a file"

See man test for more constructs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cat files listed in text file and redirect to new directory with same filename

I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Discussion started by: trigger467
5 Replies

2. Shell Programming and Scripting

extract every filename containing certain string in a directory and do some commend per file

Hi, Here is my question: suppose I have files like 1990_8xdaily_atmos.nc 1991_8xdaily_atmos.nc 1992_8xdaily_atmos.nc 1993_8xdaily_atmos.nc 1990_daily_atmos.nc 1991_daily_atmos.nc 1992_daily_atmos.nc 1993_daily_atmos.nc 1990_month_atmos.nc 1991_month_atmos.nc 1992_month_atmos.nc... (1 Reply)
Discussion started by: 1988PF
1 Replies

3. Shell Programming and Scripting

put file in different directory according to the filename

Dear all, I would like to know how to move the downloaded files in differenent directories according to the name of the file? i.e. P10120111201_122013M.jpg P10120120101_122013M.jpg P10120120201_122013M.jpg The first 4 charactors "P101" is the station name, 4-8 means year "2012",... (5 Replies)
Discussion started by: handsonzhao
5 Replies

4. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

5. Shell Programming and Scripting

FIle (directory) test operator (bash)

I'm almost pulling out my hair trying to figure out what's wrong with this... there's no reason I can see that it shouldn't be working. It seems that the code acts as though the conditional statement is true no matter what - I've even tried removing the negation operator, but it always goes into... (5 Replies)
Discussion started by: wildbluefaerie
5 Replies

6. UNIX for Dummies Questions & Answers

rm: Unable to remove directory /mnt/users/test/logs/: File exists

rm: Unable to remove directory /mnt/users/test/logs/: File exists ls -latr total 191208 drwxrwxrwx 6 test echo 4096 Jul 3 22:36 .. -rwxrwxrwx 1 test echo 97692804 Jul 3 22:36 .nfsDFA4 drwxrwxr-x 2 test echo 4096 Jul 3 23:00 . M not able to delete... (4 Replies)
Discussion started by: solitare123
4 Replies

7. Shell Programming and Scripting

how to get filename from directory

hi find /home -type f -atime +5 shows me files like : home/test/aaa.txt home/test/bbb.html How can I get the file name I mean only aaa.txt and bbb.html (19 Replies)
Discussion started by: tjay83
19 Replies

8. Solaris

test and .test in same directory

i am using solaris 5.10. i can create two different files "test" and ".test" in the same directory. now suppose i want to change the attribute of the hidden file .test to visible is it possible??? since "." is just an attribute to mark a file hidden why is unix allows creation of "file" and... (14 Replies)
Discussion started by: vikashtulsiyan
14 Replies

9. Shell Programming and Scripting

test for directory being subdir of another directory

I've been using the following code to make sure a shell script only runs under a "safe" directory. Comments/Improvements? #!/bin/sh #----------------------------------------------------------------------------# #..........................................................#... (8 Replies)
Discussion started by: hackware
8 Replies

10. Shell Programming and Scripting

test if a filename exists with specified string (ksh)

I'm trying to do a simple if statement that tests if a filename exists with a user specified string. So say I have these files: Assigned_1day_after_due_chuong Assigned_1day_after_due_gallen Assigned_1day_after_due_heidenre and i'm running a script and want to know if a... (6 Replies)
Discussion started by: bob122480
6 Replies
Login or Register to Ask a Question