Announcement

Collapse
No announcement yet.

Using elif or else if?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Code:
    echo "{}"
    Wont work as it is used internally by find only and has nothing to do with bash

    Another problem you have is that find returns 0 if it finds something or not... which makes it hard to use it in an if statement like that.

    The best way to solve this is to have one find statement and use your favorite this: -regex=pattern or -iregex=pattern to find the files

    Something like this should work:
    Code:
    find ${input} -iregex "regex pattern" -exec ...
    The only problem if finding a regex pattern that can match the file names you want which if I am correct is along the lines of:
    *.part01.rar|*.rar

    but not match things like
    *.part0[023456789].rar

    Try this,
    Code:
    find -iregex '.*\.rar' -iregex '.*[^p][^a][^r][^t].?[^023456789]\.rar'
    Although I have no idea if it will work... I could probably be made allot neater, but Its too late for trying to figure out how

    Comment


      #17
      Well that seems to be working to an extent.
      Code:
      if find -iregex '.*\.rar' -iregex '.*[^p][^a][^r][^t].?[^023456789]\.rar' -exec ark --batch --autodestination --autosubfolder '{}' '+' ; then
      But it suffers from one critical flaw, when dealing with split archives using the part0[2345], I can't tell if it is trying to handle each rar file in a recursive manner, or if it simply keeps trying to extract part01.rar in a never ending loop.
      OS: Kubuntu 12.10/Windows 8
      CPU: Intel Core i7 2600K
      Motherboard: Gigabyte GA-Z77X-UD5H
      Memory: 2x4GB Corsair Dominator
      Graphics Card: MSI R7770
      Monitor: Dell 2208WFP
      Mouse: Mionix NAOS 5000
      PSU: Corsair 520HX
      Case: Thermaltake Mozart TX
      Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
      Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

      Comment


        #18
        Originally posted by Xplorer4x4 View Post
        Well that seems to be working to an extent.
        Code:
        if find -iregex '.*\.rar' -iregex '.*[^p][^a][^r][^t].?[^023456789]\.rar' -exec ark --batch --autodestination --autosubfolder '{}' '+' ; then
        But it suffers from one critical flaw, when dealing with split archives using the part0[2345], I can't tell if it is trying to handle each rar file in a recursive manner, or if it simply keeps trying to extract part01.rar in a never ending loop.
        It is not ment to match anything with part0[023456789].rar at the end of it, so should not pass them to ark.

        Try commenting out the -exec part (place a # just before the -exec ie "... #-exec ...") and see what it prints out, once you have it printing what you want then move onto getting the ark part to work.

        Comment


          #19
          I couldnt comment it out because of the script format. I did run it straight from terminal and found that it is finding part01.rar, part11.rar, and part21.rar. So pretty much multiples of 10 starting from 01 depending on the number of archives.
          OS: Kubuntu 12.10/Windows 8
          CPU: Intel Core i7 2600K
          Motherboard: Gigabyte GA-Z77X-UD5H
          Memory: 2x4GB Corsair Dominator
          Graphics Card: MSI R7770
          Monitor: Dell 2208WFP
          Mouse: Mionix NAOS 5000
          PSU: Corsair 520HX
          Case: Thermaltake Mozart TX
          Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
          Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

          Comment


            #20
            Try this
            '.*[^p][^a][^r][^t](0[^023456789]|[^0].)\.rar'
            as the second regex

            Comment


              #21
              Make sure I didn't miss something:
              Code:
              find -iregex '.*\.rar' -iregex '.*[^p][^a][^r][^t](0[^023456789]|..)\.rar'
              Gives me no results at all.
              OS: Kubuntu 12.10/Windows 8
              CPU: Intel Core i7 2600K
              Motherboard: Gigabyte GA-Z77X-UD5H
              Memory: 2x4GB Corsair Dominator
              Graphics Card: MSI R7770
              Monitor: Dell 2208WFP
              Mouse: Mionix NAOS 5000
              PSU: Corsair 520HX
              Case: Thermaltake Mozart TX
              Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
              Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

              Comment


                #22
                Sorry, I did a sneaky edit after I realized it wouldn't work. Didn't think you would find it that quickly, try again

                Comment


                  #23
                  lol I haven;t been lately but you got me while I was still on the computer.

                  Tried the edit, still no results:
                  find -iregex '.*\.rar' -iregex '.*[^p][^a][^r][^t](0[^023456789]|[^0].)\.rar'
                  OS: Kubuntu 12.10/Windows 8
                  CPU: Intel Core i7 2600K
                  Motherboard: Gigabyte GA-Z77X-UD5H
                  Memory: 2x4GB Corsair Dominator
                  Graphics Card: MSI R7770
                  Monitor: Dell 2208WFP
                  Mouse: Mionix NAOS 5000
                  PSU: Corsair 520HX
                  Case: Thermaltake Mozart TX
                  Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                  Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                  Comment


                    #24
                    Originally posted by Xplorer4x4 View Post
                    lol I haven;t been lately but you got me while I was still on the computer.

                    Tried the edit, still no results:
                    find -iregex '.*\.rar' -iregex '.*[^p][^a][^r][^t](0[^023456789]|[^0].)\.rar'
                    Sorry, I got that completely wrong lets try again:
                    Code:
                    find -iregex '.*[^p][^a][^r][^t]..\.rar\|.*part0[^023456789]\.rar\|.*/.?.?.?.?.?.?\.rar'
                    It should match everything you want.

                    Comment


                      #25
                      Tha'ts awesome James, works perfect now, well with the exception that the service menu is not passing multiple folders to konsole. If I manually select 2 folders, it seems the script is not even executed.
                      OS: Kubuntu 12.10/Windows 8
                      CPU: Intel Core i7 2600K
                      Motherboard: Gigabyte GA-Z77X-UD5H
                      Memory: 2x4GB Corsair Dominator
                      Graphics Card: MSI R7770
                      Monitor: Dell 2208WFP
                      Mouse: Mionix NAOS 5000
                      PSU: Corsair 520HX
                      Case: Thermaltake Mozart TX
                      Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                      Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                      Comment


                        #26
                        Originally posted by Xplorer4x4 View Post
                        Tha'ts awesome James, works perfect now, well with the exception that the service menu is not passing multiple folders to konsole. If I manually select 2 folders, it seems the script is not even executed.
                        What do you have in the .desktop file?

                        Remember:
                        %u a single URL
                        %U a list of URLs
                        %f a single file
                        %F a list of files

                        Comment


                          #27
                          Yeah I know what the variables stand for. I was using %f in the konsole line since you can only use the same variable once(in this case %U). I suppose %F would have worked but I eliminated Konsole from the exec line and it works fine now. Sorry I didn't get an edit in time, but thanks for all the help! This makes my life so much easier!
                          OS: Kubuntu 12.10/Windows 8
                          CPU: Intel Core i7 2600K
                          Motherboard: Gigabyte GA-Z77X-UD5H
                          Memory: 2x4GB Corsair Dominator
                          Graphics Card: MSI R7770
                          Monitor: Dell 2208WFP
                          Mouse: Mionix NAOS 5000
                          PSU: Corsair 520HX
                          Case: Thermaltake Mozart TX
                          Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                          Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                          Comment


                            #28
                            Update here, I finally got unlazy and edited the .desktop file *not* to use konsole, the script no longer works. When tryign to use it with conosle, I get a kdialog saying "Extracting archive from ${input} complete." Yet it doesn't perform any extraction. Another slight problem, I tried to use it on a folder with a space in the name. Kdialog returned 3 pop ups. The first pop up passed "Folder A1" as the ${input}, the second passed "Folder," and the third passed "A1" as the input. I haven't tested, but in theory could changing %U to '%U' in the .desktop file? Another slight problem, probably ark related, when I enter a parent folder that has multiple child folders, and I execute the script via service menu, it places the extracted content in one of the child folders. Also, I am looking in to dropping (atleast) the first kdialog since ark already passes a kdialog pop up on a successful extraction. I assume the same holds true for a failed extraction.

                            Exec line:
                            Code:
                            #Exec=searchforarchives.sh %U
                            Bash Script:
                            Code:
                            #!/bin/bash
                            searchextractrar() {
                                input="${1}"
                                #echo "${1}"
                            
                                if find -iregex '.*[^p][^a][^r][^t]..\.rar\|.*part0[^023456789]\.rar\|.*/.?.?.?.?.?.?\.rar' -exec ark --batch --autodestination '{}' '+' ; then
                            	    kdialog --passivepopup "Extracting archive from ${input} complete." 60
                            	else
                            	    kdialog --passivepopup "No archive found or failed to extract arhives in ${input}." 60
                            	return 1  #Change to exit 1 to stop the script on first failure
                               fi
                            }
                            
                            for file in ${@} ; do
                                searchextractrar ${file}
                            done
                            Last edited by Xplorer4x4; Oct 31, 2012, 08:28 AM.
                            OS: Kubuntu 12.10/Windows 8
                            CPU: Intel Core i7 2600K
                            Motherboard: Gigabyte GA-Z77X-UD5H
                            Memory: 2x4GB Corsair Dominator
                            Graphics Card: MSI R7770
                            Monitor: Dell 2208WFP
                            Mouse: Mionix NAOS 5000
                            PSU: Corsair 520HX
                            Case: Thermaltake Mozart TX
                            Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                            Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                            Comment


                              #29
                              forgive me for butting in with a stupid question. what is the advantage of using ark instead of just unrar?
                              FKA: tanderson

                              Comment


                                #30
                                Originally posted by blobfish View Post
                                forgive me for butting in with a stupid question. what is the advantage of using ark instead of just unrar?
                                Not stupid but already answered. Namely a progress meter and built in notification handling.
                                OS: Kubuntu 12.10/Windows 8
                                CPU: Intel Core i7 2600K
                                Motherboard: Gigabyte GA-Z77X-UD5H
                                Memory: 2x4GB Corsair Dominator
                                Graphics Card: MSI R7770
                                Monitor: Dell 2208WFP
                                Mouse: Mionix NAOS 5000
                                PSU: Corsair 520HX
                                Case: Thermaltake Mozart TX
                                Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                                Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                                Comment

                                Working...
                                X