Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-31-2016, 01:31 PM
|
#1
|
LQ Newbie
Registered: May 2013
Posts: 11
Rep:
|
Help creating script to process files in folders
OK, gots a good one for you Linux gurus out there. I need to create a script that will parse a folder full of folders. In each subfolder there are several files, only one of which I need. I want to take the one file, which has a specific file extension, and move it to a different folder for further processing. The ability to specify the file extension or use multiple extensions would be a big help. I then want to be able to delete the subfolder regardless of any remaining files. The number of subfolders changes from day to day, so a for loop will probably be in order. Any help? Thanks in advance!!!
Last edited by jkellogg; 07-31-2016 at 01:32 PM.
|
|
|
07-31-2016, 02:31 PM
|
#2
|
Member
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
|
This can be done. How far have you gotten, and where are you stuck?
Best regards,
HMW
|
|
|
07-31-2016, 03:37 PM
|
#3
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,328
|
Quote:
Originally Posted by jkellogg
OK, gots a good one for you Linux gurus out there. I need to create a script that will parse a folder full of folders. In each subfolder there are several files, only one of which I need. I want to take the one file, which has a specific file extension, and move it to a different folder for further processing. The ability to specify the file extension or use multiple extensions would be a big help. I then want to be able to delete the subfolder regardless of any remaining files. The number of subfolders changes from day to day, so a for loop will probably be in order. Any help? Thanks in advance!!!
|
Not really a "good one", since this is so frequently a homework question, that there are THOUSANDS of sample scripts to do this. And you can probably even read your previous thread where you ask how to sort and move files, and where someone handed you a script:
http://www.linuxquestions.org/questi...lp-4175563871/
...and use IT as your starting point. We are happy to HELP you, but don't ask us to write your scripts.
|
|
1 members found this post helpful.
|
08-01-2016, 07:47 AM
|
#4
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,914
|
This seems a highly complicated script which requires interactive behavior? Really, think about it, something that parses tons of files in folders and then upon the whim of whatever decides to move an arbitrary file from one place to another.
That's like a file manager/organizer application.
And what in the world is wrong with:
Code:
find . -name "*.dat" -exec mv {} <where you want it to go> \;
If you're asking this question for fun, your own amusement, your own learning experience, then make some effort on your own. Note that most of us would rather write code to save our own time versus reinvent things arbitrarily. Whatever you've specified doesn't seem anything useful or more special than existing capabilities that can be done either extremely easily or by using applications which already exist.
|
|
1 members found this post helpful.
|
08-01-2016, 08:45 AM
|
#5
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
This forum is littered with such scripts.
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 04:34 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|