#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    0

    Command line: Using asterisk to select all files inside quotes for a directory name


    I'm running a command line utility on my ASP web site which takes an input of a list of file names along with other parameters. The following command works fine:

    Code:
    pdftk D:\testfolder\*.pdf other_parameter other_parameter
    But then my folder path actually has a space in it so I need to do this:

    Code:
    pdftk "D:\test folder\*.pdf" other_parameter other_parameter
    but this doesn't work because the quotes makes the asterisk a string character and does not use it as a special character anymore.

    How do I work around this without renaming folders or anything along those lines where it requires me to change the input? Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    You can try

    Code:
    pdftk "D:\test folder"\*.pdf other_parameter other_parameter
    But if I'm not mistaken, DOS makes the application do its own globbing so it might not work for your application.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    0
    Originally Posted by OmegaZero
    You can try

    Code:
    pdftk "D:\test folder"\*.pdf other_parameter other_parameter
    But if I'm not mistaken, DOS makes the application do its own globbing so it might not work for your application.
    I tried that and it didn't work. Any other suggestions? Thanks
  6. #4
  7. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,440
    Rep Power
    4539
    You could try
    Code:
    pdftk "D:\""test folder""\*.pdf" other_parameter other_parameter
    But how this all works is dependent on how the pdftk program (whatever that is) handles arguments. It's possible the program can't handle the path correctly even though you pass what appears to be a correct path.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    If you are running this through the DOS shell (cmd.exe) then the shell itself does not handle wildcard expansion - this has to be done in each program.

    You could switch to a shell that does do handle wildcards such as cygwin bash, but that uses unix conventions and I don't know if Windows pdftk will handle paths with / instead of \. You could try finding a cygwin version of pdftk and using that.

    Dave
  10. #6
  11. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    for %i in (*.pdf) do echo pdftk "%~fi" option opt flag

    - remove echo when you're happy that it's generating the right format of command
    - remove ~f if you don't want the full path
    - remove "" if you don't want "" around the filename. But if you do this, your pdftk program needs to understand raw filenames with spaces.

    for /?
    to explore more goodies.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    A quick search shows that pdftk is included with cygwin, so you could install that. The cygwin installer lets you select which programs to install with it, so make sure pdftk is selected.

    Cygwin will give you a decent shell (several shells actually - I prefer zsh to bash) and access to thousands of command line utilities.

    Dave
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    0
    Two problems with the Cygwin solutions posted:

    1) I'm not sure I will be able to install Cygwin on the web server

    2) How would I call Cygwin from an asp page? Right now I'm using Set oExec = WshShell.Exec (command goes here)

IMN logo majestic logo threadwatch logo seochat tools logo