Sponsored Content
Homework and Emergencies Homework & Coursework Questions Problem while traversing directories Post 302611621 by davis7son on Friday 23rd of March 2012 07:59:39 AM
Old 03-23-2012
Problem while traversing directories

I was given to create a backup of all files in a given directory(command line argument) into say /home/vishal/back and the back up files must be accordingly to the extension of the file i.e pdf files are saved in back/pdf doc files back/doc etc . I gave a recursive function to traverse through the given directory but im getting correct answers until this case exists

say the user gave user/yyy and lets say directroy yyy contains 2 directories xxx and zzz and one file say op.doc. If say xxx has 2 other directories and also some file,(there is no error when there is only directories and no file ). Here is my code ... please help


recur() <<<<recursive function>>>>>
{
echo $1
cd $1
for i in *
do
if [ -d $i ]
then recur $1/$i

else
filename=$i
extension=$(echo ${filename}|awk -F\. '{print $2}')
cd /home/vishal/back
count=0
for p in *
do
typ=$(echo ${p})
if [ $extension = $typ ]
then count=1
break
fi
done


if [ $count -eq 1 ]
then cp $1/$filename /home/vishal/back/$typ/
else
mkdir /home/vishal/back/$extension/
cp $1/$filename /home/vishal/back/$extension/
fi

fi

done
cd $1
cd ..
}

recur $1 <<<<$1 is user given directory>>>>>>>


Lovely University, India , Prof Kumar Patel, CS Engineering
This User Gave Thanks to davis7son For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Traversing a file system

I'm pretty new at this UNIX stuff, and this may be a simple question but I'm kind of stuck :confused: Let's say I have a large directory structure of .essay files, where I saved all of the essays that I did over the last few years. Not all of the .essay files are in the same directory (all... (1 Reply)
Discussion started by: hooj
1 Replies

2. Shell Programming and Scripting

Traversing thru dirs and deleting files based on date

Hi Folks I am pretty new to unix and shellscripting. I need help on writing logic on traversing recursively through a set of directories under a top-level folder and delete files(mostly text) which are 1 month old. Can you people help me on this? Thanks a lot Ravi (5 Replies)
Discussion started by: ravi2082
5 Replies

3. UNIX for Dummies Questions & Answers

Traversing Pascal/Delphi code using GVim

Hi, I am using GVim as editor... and i am viewing code of pascal/ delphi.. my problem is its difficult to use GVim as source code browser.... normally ctags helps to traverse in vim for c/c++.. is there anything like that for pascal/ delphi to minimise this complication of each... (0 Replies)
Discussion started by: SankarV
0 Replies

4. Programming

Vector Traversing

Hi i have the following structure struct S { char Mod_num; char val; char chr_nm_cd; } I am reading a 2GB file and inserting into the structure and writing into a vector. I feel like only vector will be a right option. I tried with multimap but it is memory intensive and hence i... (1 Reply)
Discussion started by: dhanamurthy
1 Replies

5. UNIX for Dummies Questions & Answers

script for traversing directory

hi please suggest a korn script which will traverse all subdirectory in the current directory? (2 Replies)
Discussion started by: ilayans
2 Replies

6. Shell Programming and Scripting

Find directory name while traversing subdirectories

Hi, I have a parent directory in which I have sub directories of different depth /usr/usr1/user2/671 /usr/usr1/672 /usr/user2/user1/673 /usr/user2/user3/user4/674 And I need the names of all the directories that which starts only with 6 in a file. Thanks, (12 Replies)
Discussion started by: arun_maffy
12 Replies

7. Programming

Traversing in Array of pointers

Please find the below program. the requirement and description of the program also given: ganesh@ubuntu:~/my_programs/c/letusc/chap9$ cat fa.c.old /* Program : write a program to count the number of 'e' in thefollowing array of pointers to strings: char *s = { "We will teach you how... (12 Replies)
Discussion started by: ramkrix
12 Replies

8. Shell Programming and Scripting

traversing a string

I am writing a script which will read a word and say how many vowels and consonants does the word contain. but i dont know how to traverse a string in shell scripting. if it was in C i'd have done something like this: cout<<"plz enter the word"<<endl; cin>>word; int consonants, vowels;... (4 Replies)
Discussion started by: nishrestha
4 Replies

9. Programming

How to reverse a linked list by traversing only once.?

Program to reverse a linked list by traversing only once. (1 Reply)
Discussion started by: VSSajjan
1 Replies

10. Programming

Traversing member of structure of vector C++

Hello, I want to loop thru a vector composed of many entries as structure, which contains sequenceID and sequence. At looping, delete any structure if the sequence is a perfect-match substring of another sequence of any other structure, so that the resulted vector contains only unique sequences.... (1 Reply)
Discussion started by: yifangt
1 Replies
DMX(3)							     Library Functions Manual							    DMX(3)

NAME
DMX - X Window System DMX (Distributed Multihead X) extension DESCRIPTION
The DMX extension provides support for communication with and control of Xdmx(1) server. Attributes of the Xdmx(1) server and of the back- end screens attached to the server can be queried and modified via this protocol. SUMMARY OF LIBRARY FUNCTIONS
The following is a summary of DMX library functions: DMXQueryExtension(3) - determine if DMX is available DMXQueryVersion(3) - determine DMX extension version DMXSync(3) - flush protocol requests between Xdmx(1) and back-end X servers DMXForceWindowCreation(3) - force immediate back-end window creation DMXGetScreenCount(3) - determine number of back-end screens DMXGetScreenAttributes(3) - determine back-end screen attributes DMXChangeScreensAttributes(3) - change back-end screen attributes DMXAddScreen(3) - attach a new back-end screen DMXRemoveScreen(3) - detach a back-end screen DMXGetWindowAttributes(3) - determine back-end window attributes DMXGetDesktopAttributes(3) - determine global bounding box DMXChangeDesktopAttributes(3) - change global bounding box DMXGetInputCount(3) - determine number of input devices DMXGetInputAttributes(3) - determine input device attributes DMXAddInput(3) - attach a new backend or console input DMXRemoveInput(3) - detach an input DMXAddBackendInput(3) - attach a new back-end input DMXAddConsoleInput(3) - attach a new console input Each of these functions is described in its own man page. SEE ALSO
Xdmx(1), xdmxconfig(1), vdltodmx(1) X Version 11 libdmx 1.1.2 DMX(3)
All times are GMT -4. The time now is 12:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy