Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 2nd May 2009, 22:52
PatrickMc PatrickMc is offline
Junior Member
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Default How to move text files to parent folder

Someone had asked a scripting question about how to move all .txt files to their respective parent folders. I can't post an answer there since when I click REPLY, it shows me a blank screen.

Anyway, here are the requirements.

Quote:
Start with folder folder1, find files *.txt in the folder and subfolders, move all .txt files back one level up (into parent folder).
Here is the script.

Code:
var str list ; lf -rn "*.txt" "folder1" > $list
while ($list <> "")
do
    var str file ; lex "1" $list > $file
    # $file now has the full path of one file. Strip off the last instance of
    # /.../ . If that does not exist in full path, this file is at the top level.
    var str parent ; stex -r -p "]^/&/^" $file > $parent
    if ($parent=="")
        # There is no parent folder to copy this file to.
        echo $file " is already at the top-most level directory."
    else
        system move ("\""+$file+"\"") ("\""+$parent+"\"")
    endif
done
This script is in biterscripting ( http://www.biterscripting.com/install.html ) .


Patrick
Reply With Quote
The Following User Says Thank You to PatrickMc For This Useful Post:
falko (3rd May 2009)
Sponsored Links
  #2  
Old 3rd May 2009, 17:49
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,727 Times in 2,565 Posts
Default

Quote:
Originally Posted by PatrickMc View Post
I can't post an answer there since when I click REPLY, it shows me a blank screen.
Hi Patrick,

can you tell me which browser and browser version you're using, and which OS? Does your browser accept cookies from HowtoForge?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 8th May 2009, 03:06
nicephotog nicephotog is offline
Junior Member
 
Join Date: Nov 2008
Location: Australia
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try this at the prompt and that is as much as required in basic to move multiple files and you will see that you need to organise how a script requires to runthrough folders for each folder.

This picks up all the .txt files present in the folder and moves them to the parent directory . In effect it is also setup for the prompt if you have CD'd into the directory first.
-b alike backup
-i prompt an overwrite
-v verbose

mv -biv *.txt ../
Reply With Quote
  #4  
Old 8th May 2009, 19:00
PatrickMc PatrickMc is offline
Junior Member
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Default biterscripting mv (system) command

nicephotog:

Thanks for your tip. But if you were to execute the mv command from the command prompt, you would have to do this folder by folder - first cd to a folder, then do mv. No ? (I guess the original poster was looking for a script to do all of that in just one command.)

falko:

Thanks for your consideration. Actually, it (the blank screen) is not happening here. I am able to post a reply here. So, I guess that was only a temporary phenomenon.

Patrick
Reply With Quote
  #5  
Old 15th July 2009, 05:38
mdjzh mdjzh is offline
Junior Member
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I like the idea, cool!
__________________
no better runescape accounts, just best runescape accounts!
Reply With Quote
  #6  
Old 15th July 2009, 08:19
nicephotog nicephotog is offline
Junior Member
 
Join Date: Nov 2008
Location: Australia
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
 
Default

Sorry , That was a bit short for the idea at it

Code:
# guess where ./ is I should have said "something like this" in the previous
# sorry i don't have a linux box with me for now 
# no qw
manillas=("./contfol1/fnum1" "./contfol2/fnum2" "./contfol3/fnum3")
#
mlen=${#manillas[@]}
#
for ((i=0;i<${mlen};i++)); # double brackets for numerics
do
mv -biv ${manillas[$i]}/*.txt ../
done
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ffmpeg Video support for ubuntu 7.10 [suphp-ispconfig] amaurib Installation/Configuration 13 16th February 2010 17:26
The system is currently updating the configuration files. warlock General 8 21st February 2009 18:15
Symbolic link to all files of a folder hhhhhh Installation/Configuration 0 3rd February 2009 02:32
Move junk mail to a folder instead of deleting grant Tips/Tricks/Mods 20 22nd October 2008 23:09
How to keep in RAM a number of text files? calande Server Operation 2 7th January 2008 17:17


All times are GMT +2. The time now is 17:04.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.