ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Using QShell To Get A List of FilePath's

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using QShell To Get A List of FilePath's

    I need to generate a listing of file paths that match a string. Take the following folder structure:

    Code:
    myfolder
      mysubfolder1
        123456.dat  (this is a file)
        123456 (this is a folder)
        654321.dat
        654321
      mysubfolder2
        123456.dat  (this is a file)
        123456 (this is a folder)
        654321.dat
        654321

    So as you can see, file names and folder names are not unique within the folder structure, but are unique by folder/file path. However, the listing it generates is broken up by folder structure:

    Code:
    ls -1lAR /myfolder > /a-qsh-output.txt
    Code:
    /myfolder/mysubfolder1:
    total: 391 kilobytes 
    drwxrwxrwx  2 NFSUSER  NFSGROUP                    64 Mar 23 13:33 123456    
    -rwxrwxrwx  1 NFSUSER  NFSGROUP                   589 Feb 25 06:30 123456.dat
    
    /myfolder/mysubfolder1/123456:
    total: 31kilobytes 
    -rwxrwxrwx  1 NFSUSER  NFSGROUP                   589 Feb 25 06:30 00001.pdf
    
    /myfolder/mysubfolder2:
    total: 32 kilobytes
    drwxrwxrwx  2 NFSUSER  NFSGROUP                    64 Mar 23 13:33 123456    
    -rwxrwxrwx  1 NFSUSER  NFSGROUP                   589 Feb 25 06:30 123456.dat
    
    /myfolder/mysubfolder2/123456:
    total: 31kilobytes 
    -rwxrwxrwx  1 NFSUSER  NFSGROUP                   589 Feb 25 06:30 00001.pdf
    Notice how the result is broken up. I'm looking for a way to produce output that is 1 file/folder per line only (no additional information). All I would like to see is this:

    Code:
    /myfolder/mysubfolder1/123456.dat
    /myfolder/mysubfolder1/123456/00001.pdf
    /myfolder/mysubfolder2/123456.dat
    /myfolder/mysubfolder2/123456/00001.pdf
    Hopefully that makes sense.

  • #2
    Re: Using QShell To Get A List of FilePath's

    No qshell expert, but this works for me - to find files that start with 123 and generate a plain list of just the file names:
    ls 123* > filelist.txt

    Cheers,

    Emmanuel

    Comment


    • #3
      Re: Using QShell To Get A List of FilePath's

      Originally posted by EmmanuelW1 View Post
      No qshell expert, but this works for me - to find files that start with 123 and generate a plain list of just the file names:
      ls 123* > filelist.txt

      Cheers,

      Emmanuel
      Thanks for your reply. However, this only produces a single level listing. I need all subfolders and files within those subfolders.

      Comment


      • #4
        Re: Using QShell To Get A List of FilePath's

        try
        -R Displays subdirectories as well.
        Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

        Comment


        • #5
          Re: Using QShell To Get A List of FilePath's

          Originally posted by DeadManWalks View Post
          try
          -R Displays subdirectories as well.
          That produces the result I listed above in the original post.

          Comment


          • #6
            Re: Using QShell To Get A List of FilePath's

            Zenbudda,

            How about taking the "/a-qsh-output.txt" file with all that extra stuff and then running through some form of SQL so that it only picks lines with the slashes... and writes those lines to a second file?


            Regards,

            Fred

            Comment


            • #7
              Re: Using QShell To Get A List of FilePath's

              You could generate the initial output and then do another action on the output file (No expert but grep should give you the results??) I would just use the API Qp0lProcessSubtree, the only problem is the way the output is generated may not be in the order you require? Perhaps you can sort after?

              Chris...

              Comment


              • #8
                Re: Using QShell To Get A List of FilePath's

                Thanks Chris.

                After doing some research, I came across the "find" command.

                Code:
                find /folder/folder/ -type f -name '*.dat'
                My CL program overrides STDOUT so that I can trap the output to a PF. This seems to get me what I need.

                Comment


                • #9
                  Re: Using QShell To Get A List of FilePath's

                  Sorry for the slow response. The 'find' tool is definitely the way to go for this sort of thing. I would not even consider using 'ls' here -- I almost always prefer 'find' for programs/scripts. (ls is better for humans to read, though.)

                  Comment

                  Working...
                  X