Find the answer to your Linux question:
Results 1 to 2 of 2
Hello All, I am writing script in bash as follows -> I have to take a files ( Image files .jpeg) from a directory ( source directory ) one by ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    45

    How to take the files from a directory and remove after process

    Hello All,


    I am writing script in bash as follows

    -> I have to take a files ( Image files .jpeg) from a directory ( source directory ) one by one
    -> cut the file in to 3 parts
    -> remove the middle part and store the 2 parts in another directory ( destination directory )
    -> after cut remove the file from the source directory
    -> it has to do for all the files in a source directory .( assume 100 files )

    assume source directory as 100 files

    the following the code i written I dont kow how to continue?

    please help me out

    Code:
    #!/bin/sh
    
    #take the file from source directory
    
    var=`ls -t /home/sud/desktop/jpeg | head -n 1`
    
    #cut the image into 3 parts
    
    convert -crop <Dimension> soursefile.jpeg destinationfile.jpeg

    problem is how to make loop and how to delete one of them in 3

    because cut files are stored in a destination directory in a order - filename-0.jpeg ,filename-1.jpeg filename-2.jpeg

    i have to remove filename-1.jpeg

    thanks in advance

  2. #2
    Just Joined!
    Join Date
    Oct 2008
    Posts
    10
    I assume when you want to cut the file in 3 parts you mean to store the content of the file in 3 different files

    #!bin/bash

    cd $source_directory

    for myfile in * #all your files in source_directory will be processed!
    do
    #somehow get the 3 parts from the file being processed
    $file-0.jpeg=...
    $file-1.jpeg=...
    $file-2.jpeg=...
    #copy interesting parts to destiny_directory (the parts should be files)
    cp ./$file-0.jpeg $destiny_directory
    cp ./$file-2.jpeg $destiny_directory
    rm $myfile
    done

    NOTE: take care not to store this script in source_directory, it would be wiped out by the for loop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...