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




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)
## If in subfolder more than one .pdf or more than one .txt file, I must miss this subfolder (move it to Folder3 - it's one of the folders of my user's home dir) ;

4. I must to scan every subfolders in folder1,
enter in each one;
5. If this subfolder has more than one .pdf file or more than one .txt file, I must go to next subfolder (with moving this subfolder to Folder3);
6. In «good» subfolders I must take file content.txt;
7. It has such structure:

dfdf{some trash}wqwq
info info ... info
dfdf{some trash}wqwq

8. In this file content.txt I must find and cut only «useful_info» (between begin_of_useful_info and end_of_useful_info,including it):

info info ... info

( begin_of_useful_info and end_of_useful_info is key-words on each content.txt, it must be cutted too)

9. this info I must put in new .txt file with name as .pdf file in this subfolder!

In folder1/4323353/ I have files GHTY34.pdf and content.txt. So, after operation I must get a file GHTY34.txt with useful_info)

10. delete parsed file content.txt
(so, now I have again two files in subfolder somename.pdf and somename.txt)

11. then I must copy files .pdf and new .txt with similar names somewhere, for example in folder2 (my user's home dir) and delete analized subfolder.
12. Go to next subfolder.

That's all

This will be cost one hundred US dollars

Jetty ★★★★★

В топике готовый текст программы, осталось только интерпретатор написать

unC0Rr ★★★★★

You can use Java, and google for walking through directory structure.

For example:

Also you can use existing solutions such as DirectoryWalker class of the Apache Commons IO project (

Next, you can modify your files using java built-in methods (google about «how to read and write text files in java».

Next, you can remove and copy files by hands or by using Apache Commons api.


stevejobs ★★★★☆

Don't listen to fake steve, optik77. He is brain damaged. java, oh god *puke*


find ~/folder1 -maxdepth 0 -type d | while read folder; do
  if [ 1 -ne $(ls "$folder/*.pdf" |wc -l) ] ||
     [ 1 -ne $(ls "$folder/*.txt" |wc -l) ] ||
     [ ! -f "$folder/content.txt" ] ; then
     mv "$folder" ~/folder3/
  BNAME=$(basename "$folder/*.pdf" .pdf)
  awk 'BEGIN { found=0 }
/^begin_of_useful_info$/ {found=1}
/^end_of_useful_info$/ {found=0;print $0}
{if (found)print $0}
' "$folder/content.txt" > $FNAME
  mv "$folder/$BNAME.txt" "$folder/$BNAME.pdf" ~/folder2/
  rm -rf "$folder/"

Didn't tested this code because of windows. I'll check myself when I return home to my computer with a real operating system.

PS wtf this shit I cannot reply in Development anonymously anymore

PPS obviously you aren't a real English-speaker and question is purely synthetic but I don't care lol

PPPS thanks to opennet for man test and man find.

legolegs ★★★★★
Ответ на: комментарий от stevejobs

Java is bad choice. It is not native and need additional installed software. Use Python with additional frameworks is better idea.

Also you can write your own Perl module for same tasks.

In that way your problem will be resolved forever.

Chief of galaxy NT problems department
Syava Izgoldovish

Jetty ★★★★★

«Inglesh is spocken hier» (ц)

Xenesz ★★★★
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.