Help modifying script to loop through all folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help modifying script to loop through all folders
# 1  
Old 09-22-2008
Help modifying script to loop through all folders

I have this script someone very kindly help me write last year which loops through all files in a folder and does a command.

I need to modify it to loop through all sub-folders of a main folder and only perform the command on files modified after Jan 1st 2008. And I need the command to place the new created files in a new sub folder.

Here is the original script:

Code:
#!/bin/sh

for file in *
do
    newname="$file".txt
    expage "$file" >"$newname"
    echo "Expaged $file to $newname"
done

# 2  
Old 09-22-2008
Come to think of it, all I need the script to do is copy all the files that were modified after Jan 1, 2008 to a new folder.
# 3  
Old 09-22-2008
Not very clear if you resolved the problem, but from your first request you can try the following,

Code:
#!/bin/sh

cd /path/to/main_folder
mkdir new_subfolder

find . -type f -mtime -265 | while read file
 do
    newname="$file".txt
    expage "$file" >"$newname"
    echo "Expaged $file to $newname"
    cp -p "$newname" new_subfolder/
    # mv "$newname" new_subfolder/
 done

Change the no. of days ( 265 ) to whatever number you need.
# 4  
Old 09-22-2008
Quote:
Originally Posted by rubin
Change the no. of days ( 265 ) to whatever number you need.
You don't really need a number.
Code:
find . -type f -atime -"$(($(date "+%j" ) - 1 ))" | while read file
...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to loop through folders and execute an existing python script.

I am trying to loop through lots and lots of folders and use the names of the folders to run a Python script which has parameters. E.g. -- setup_refs -n John -f England/London/Hackney/John -c con/con.cnf Normally to run `setup_refs` once from command line it's: `python setup_refs.py -n John... (3 Replies)
Discussion started by: Mr_Keystrokes
3 Replies

2. UNIX for Beginners Questions & Answers

Loop through the folders and search for particular string in files

Hello, Opearting System Environment : HP Unix B.11.31 U I look for script to On specific folders list On specific filelist Search for given string For Example : r48_buildlib.txt contains wpr480.0_20161027 wpr480.0_20161114 wpr481.0_20161208 wpr482.0_20161222... (4 Replies)
Discussion started by: Siva SQL
4 Replies

3. Shell Programming and Scripting

Bash directory loop, but only choose those folders with specific word in it

Hello, how in bash i can get directory loop, but only choose those folders with specific word in it, so it will only echo those with specific word #!/bin/bash for filename in /home/test/* do if ; then echo $filename; fithx! (4 Replies)
Discussion started by: ZerO13
4 Replies

4. UNIX for Beginners Questions & Answers

How to loop command over folders in a directory?

Hello all, I'm fairly new to scripting so please bear with me. I will try to explain as best as I can but if there's anything that is not clear, please let me know. I have a directory (see below) with numerous folders and within each of those folders are various files. I would like to run a... (11 Replies)
Discussion started by: azurite
11 Replies

5. Shell Programming and Scripting

Need some help modifying script

I have a script that currently runs fine and I need to add or || (or) condition to the if statement and I'm not sure the exact syntax as it relates to the use of brackets. my current script starts like this: errLog="/usr/local/website-logs/error.log" apacheRestart="service httpd restart"... (3 Replies)
Discussion started by: jjj0923
3 Replies

6. Shell Programming and Scripting

Some manipulations with files and folders. (loop, find, create and remove)

Hello! I need to realize such task. 1. In my user's home dir I have folder1; 2. In folder1 I have some (various count) subfolders with random names; 3. In these subfolders I have one file anyname.pdf (various name in each subfolder) and file content.txt (constant name in each subfolder) ##... (7 Replies)
Discussion started by: optik77
7 Replies

7. Shell Programming and Scripting

Loop folders, delete files, copy new ones

Folks, I am hopeful that you may be able to help me out with writing a script that can be run nightly (as cron?) to loop through all subfolders within the "/media" directory, delete all of the files in each of them, and then copy in all of the files from the "/home//sansa" directory to each of... (6 Replies)
Discussion started by: acraig
6 Replies

8. Shell Programming and Scripting

Loop through folders and open them

Well the title says it all. I need a loop script that directs to a folder and opens a bash file. I just found out about loop files the other day and yeah, dont know if that can be done. (6 Replies)
Discussion started by: snoopy817
6 Replies

9. Shell Programming and Scripting

need help with understanding and modifying script

hi all, i am new to UNIX. this is my first time using Ubuntu. i need to do this for my fyp. i am using an artificial neural network model to predict the yield strength of steel. the shell script used to execute this model is as shown here: #Thomas Sourmail, Cambridge University /... (4 Replies)
Discussion started by: dakkorn
4 Replies

10. Shell Programming and Scripting

script to loop around folders

I have a folder called {homedata} Within this folder there are 12 subfolders 200601.......200612 Within each subfolder there are 8 sets of files Each filename commences with A B C D E F G or H, so {filename}* can be used. I am trying to write a script which will from the top level go... (2 Replies)
Discussion started by: grinder182533
2 Replies
Login or Register to Ask a Question