Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Folder selection/creation with Zenity or similar

  • 24-07-2011 02:50PM
    #1
    Moderators, Arts Moderators Posts: 36,040 Mod ✭✭✭✭


    I'm trying to make a script a little more user-friendly by letting him/her select a folder to copy files into or create one if it doesn't exist. I've been able to use Zenity to select a specific file but there doesn't seem to be an option for folders. Is there any other similar packages to zenity that will allow folder creation or a hidden option in zenity?


Comments

  • Registered Users, Registered Users 2 Posts: 14,081 ✭✭✭✭Johnboy1951


    --directory option appears to be what you need .... ?

    From the man page ....
    File selection options
    --filename=FILENAME
    Set the file or directory to be selected by default
    --multiple
    Allow selection of multiple filenames in file selection dialog
    --directory
    Activate directory-only selection
    --save
    Activate save mode
    --separator=SEPARATOR
    Specify separator character when returning multiple filenames
    --confirm-overwrite
    Confirm file selection if filename already exists
    --file-filter=NAME | PATTERN1 PATTERN2
    Sets a filename filter


    zenity --file-selection --directory


  • Moderators, Arts Moderators Posts: 36,040 Mod ✭✭✭✭pickarooney


    Ah, a command within a command. I needed to go deeper than the --help switch. Thanks!


  • Moderators, Arts Moderators Posts: 36,040 Mod ✭✭✭✭pickarooney


    Still on zenity, does anyone know how or if it's possible to get the progress bar to work for file copying? It just seems to have two states, empty and full, when I pass a copy job to it, either with a large file or a set of small files.


  • Registered Users, Registered Users 2 Posts: 14,081 ✭✭✭✭Johnboy1951


    Still on zenity, does anyone know how or if it's possible to get the progress bar to work for file copying? It just seems to have two states, empty and full, when I pass a copy job to it, either with a large file or a set of small files.

    Try something like this ....
    	(
            echo ; sleep 3 
    
    <copy command or a series of commands>
    
    	echo ; sleep 3
    	) |
    		zenity --window-icon=$ICON --progress --pulsate --title="   $TITLE   " --text " <Your text here>" --auto-close --auto-kill ;
    

    Note: That is a 'pipe' after the closing bracket. Replace the variables with your own of course.

    Hope that works for you.

    regards.


  • Moderators, Arts Moderators Posts: 36,040 Mod ✭✭✭✭pickarooney


    I had tried it with just one sleep 1 command inside a copy for loop but I'll fiddle around with longer settings and see.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 14,081 ✭✭✭✭Johnboy1951


    I had tried it with just one sleep 1 command inside a copy for loop but I'll fiddle around with longer settings and see.

    The sleep commands should make no difference.
    Watch the syntax and it should work .... run in a terminal to see if it reports errors.

    Try this small script to see if it runs and closes properly

    #!/bin/bash
    
    (
            echo ; sleep 3 
    
    echo  # in place of a command
    
    	echo ; sleep 3
    	) |
    		zenity  --progress --pulsate --width=360 --title="   TEST   " --text "             Test Progress Window" --auto-close --auto-kill ;
    

    EDIT:
    Omitting 'auto-close' will cause the progress window to stay displayed until you click the 'OK' button.


  • Moderators, Arts Moderators Posts: 36,040 Mod ✭✭✭✭pickarooney


    Your test example works fine but with the following (just moving photos from a camera to hard drive) I get the same as earlier - just 0 progress for ages and then complete.
    (
    mv $CAM/DCIM/*/*.* "$DIRPATH"/tmp
    echo; sleep 1
    )|zenity --progress --pulsate --width=360 --title="File Copy " --text "Copying files..." --auto-close
    


  • Registered Users, Registered Users 2 Posts: 14,081 ✭✭✭✭Johnboy1951


    Your test example works fine but with the following (just moving photos from a camera to hard drive) I get the same as earlier - just 0 progress for ages and then complete.
    (
    mv $CAM/DCIM/*/*.* "$DIRPATH"/tmp
    echo; sleep 1
    )|zenity --progress --pulsate --width=360 --title="File Copy " --text "Copying files..." --auto-close
    


    I would suspect the command so .... for instance it works fine here when moving files between partition.

    Does the command work without the progress window?

    Is the source path OK? Are there any spaces in the path?
    Maybe enclose the source path in "<path>" ?

    Is the destination writeable by the owner of the script?

    I suggest you create a small script with static paths .... or use the variables and apply the path to the variable in the script.
    Then launch it from a terminal and see if any errors are reported.
    Without such there is not much else to do ...


  • Moderators, Arts Moderators Posts: 36,040 Mod ✭✭✭✭pickarooney


    The move command works fine; I've been using it for years. It's just that rather than having the progress bar move it stays at 0 until the files have been transferred and then it jumps to 100% and closes. I guess it's something to do with the move command itself not sending back any info as to how far it has progressed so zenity has nothing to work with. I'll test by replacing mv with rsync.


  • Registered Users, Registered Users 2 Posts: 14,081 ✭✭✭✭Johnboy1951


    The move command works fine; I've been using it for years. It's just that rather than having the progress bar move it stays at 0 until the files have been transferred and then it jumps to 100% and closes. I guess it's something to do with the move command itself not sending back any info as to how far it has progressed so zenity has nothing to work with. I'll test by replacing mv with rsync.

    There is no problem with the mv command itself.
    I have used it in such situations.

    It is probably something to do with the paths used in the command.

    Try it moving a file from one fixed partition to another ..... it will work.

    As I posted previously .... put that section in a small script and run it from a terminal and see what errors are thrown up.

    Everything else is guesswork.


  • Advertisement
Advertisement