Announcement

Collapse
No announcement yet.

shell "dir *.* > list.txt"

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

  • shell "dir *.* > list.txt"

    I am having problems using powerbasic to sort some files. The files have loing file names and what I am trying to do is generate a list of the files with a given string in them. Regardless of whether I do
    shell "dir 12345*.txt /b > list" or shell to a batch file with the same dir command in it the long file names are returned in the short file name format. When I execute the batch file from the command prompt I get the long file names as expected.
    I saw a similar post http://www.powerbasic.com/support/pb...long+file+name where someone was having a similar problem but the replies to the post didn't help me as I couldn't get the replies to work.
    I am using windows xp and eventually I want to be able to get the following dir command to work
    dir *12345*54321*.txt > list.txt
    I would prefer it to work from a shell command but if i have to run in from a shelled batch file i could live with that too.

    Thanks in advance

  • #2
    You want long names?
    Then use a DIR option which returns long names.
    Code:
    C:\DOS> dir /? | more
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      You might need to use the /N switch, which puts the long filenames to the right of the date/time...
      ???
      -John

      Comment


      • #4
        >You might need to use ...

        ...something suggested by the help ("DIR /?") ?????
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          I am after the long file names.
          To the best of my knowledge it isn't my usage of the DIR command. It is something to do with the way that powerbasic interfaces with DOS in the shell mode.
          Both at the command prompt and in a batch file DIR /b *.* > list.txt will give me a list with long file names. However when I try doing it from a shell it changes them to short file names .

          Comment


          • #6
            If I'm reading you right, this might help:

            PowerBASIC and related source code. Please do not post questions or discussions, just source code.
            There are no atheists in a fox hole or the morning of a math test.
            If my flag offends you, I'll help you pack.

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              >You might need to use ...

              ...something suggested by the help ("DIR /?") ?????
              No. It was suggested by years of experience with DOS, and the transition to Windoze that occurred circa 1995... I didn't need to look this one up.

              When I first got XP, I set the DIR command permanently to "/N" (although I can't for the life of me remember now how I did that). To see the old, original format, I use: DIR /-N

              Comment


              • #8
                Originally posted by Alan Hanson View Post
                I am after the long file names.
                To the best of my knowledge it isn't my usage of the DIR command. It is something to do with the way that powerbasic interfaces with DOS in the shell mode.
                Both at the command prompt and in a batch file DIR /b *.* > list.txt will give me a list with long file names. However when I try doing it from a shell it changes them to short file names .
                IIRC, the /B switch will interfere with the long filenames you can get via the /N switch.

                I don't recall the /B switch having much value...

                Comment


                • #9
                  Hi,

                  if I
                  Code:
                   shell "dir *.* /N"
                  I will get a error that /N is not allowed. When I start it direktly in the CMD it works. So I think you can't use a DOS Programm to get the long names.

                  But you can make a CMD file, first build the textfile with dir ... and then read the textfile with your dos programm.
                  Regards,
                  Hubert

                  ------------------------------------
                  http://familie-brandel.de/index_e.html

                  Comment


                  • #10
                    What about:

                    Code:
                    shell "cmd /c dir /N *.*"

                    Comment


                    • #11
                      When I first got XP, I set the DIR command permanently to "/N" (although I can't for the life of me remember now how I did that). To see the old, original format, I use: DIR /-N
                      Possibly you set DIRCMD /N in System Properties / Advanced / Environmental Variables ?

                      You can override with /-N (as you said).

                      PB Statement ENVIRON$ can be used to check the current setting.
                      Rgds, Dave

                      Comment


                      • #12
                        Thanks for the help guys. After trying heaps of combinations I got the following to produce the desired results.
                        shell "cmd /c dir *12345*.* /b"
                        I'm not sure what the cmd /c does but it did the trick

                        Comment


                        • #13
                          > ... I'm not sure what the cmd /c does but it did the trick

                          Try

                          Start, Run..., cmd /k

                          and then

                          cmd /?

                          to see the small help!
                          "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

                          Comment


                          • #14
                            I do not have PB DOS available now, so I cannot check it all out, but I suspect this is why this happens (consider this as speculation, but it will explain why):

                            PB DOS's 'shell "dir *.* > list.txt"' will expect a 16-bit DOS shell as it has its roots in the 16-bit, 8.3 character file name world of MS. So it either has its own built-in 16-bit COMMAND.COM clone in order to speed things up or it will start the current COMMAND.COM shell - which may or may not support LFN. In the W9x world COMMAND.COM supports LFN, as will COMMAND.COM in the WNT+ world. No matter how - you're at the shell's (COMMAND.COM's) mercy, but above DOS 6.x they should still support LFN.

                            I doubt - due to PB's strong no bloatware policy - that PB has implemented its own full COMMAND.COM. I do think it is more probable that PB DOS has implemented its own version of the most-often-used DOS shell commands (where "dir" certainly belongs) and would start COMMAND.COM for other uses, e.g. if you were to start a BATCH file. If this is what is being done, it increase speed and reduce bloatware - at the cost of [future] compatibility in the 'dir'-command's case.

                            If you specify the shell to use, you are free to specify one that do support LFN - and CMD.EXE under WNT+ will. So, by specifying
                            Code:
                            'shell "CMD.EXE /c dir *.* > list.txt"
                            you basically tell PB DOS to start CMD.EXE and then issue whatever command you specify for CMD.EXE to execute. And this does the trick. Shelling to COMMAND.COM using the same parametres should do the same trick in dir's case, and it will be compatible with W9x and DOS as well (but below W9x LFN will not be supported, of course - but there's things like FreeDOS that do).

                            Also, if you are SHELLing often enough, you should take the time to check out what CMD.EXE (or COMMAND.COM) can and cannot do for you. Start a console window and issue the "CMD.EXE /?" command to get to the help-screen. It will also explain the "/C"-switch which is crucial in this context.

                            ViH

                            Comment


                            • #15
                              Originally posted by Dave Biggs View Post
                              Possibly you set DIRCMD /N in System Properties / Advanced / Environmental Variables ?
                              ...
                              PB Statement ENVIRON$ can be used to check the current setting.
                              Nope. No DIRCMD showing with either: SET from a CMD window, nor a PB loop through ENVIRON$. Not under ControlPanel>Environment Variables. No special settings in my shortcuts for CMD, either, and I've made no mods to AUTOEXEC.NT

                              I searched the registry for DIRCMD, DIR /N, and COMMAND PROCESSOR, but none of them showed anything...

                              Now I'm stumped - where could that setting be?

                              Just out of curiosity, what is the default for DIR under XP? Short names to the left of the date/time, or long names to the right?

                              Maybe I'm remembering using /-n for the old DOS-style...

                              Comment


                              • #16
                                Originally posted by Alan Hanson View Post
                                Thanks for the help guys. After trying heaps of combinations I got the following to produce the desired results.
                                shell "cmd /c dir *12345*.* /b"
                                I'm not sure what the cmd /c does but it did the trick
                                While SHELL does run a command processor, I seem to recall that as far back as DOS, "first level" command processors sometimes have problems with control and communication back to the parent, whereas their children don't. So as a workaround/hack, we often just used the first-level cp to invoke a child cp, and ran the command there. Especially if we knew it would not require user interaction, and would only perform limited work.

                                All that "cmd /c" does is to start another command processor and the /c switch instructs it to terminate when the command it's running is finished. (Another switch, /K, also invokes a secondary processor, but it does NOT self-terminate when the command it's running is finished.)

                                In the Help file under DIR, see "Restrictions" - it mentions that DIR is an internal DOS command and SHELL needs to see the /C switch. It's actually shown in the Example, too.

                                Comment


                                • #17
                                  If you want a 16-bit COMMAND.COM (MS-DOS), the XP has one - at least in the Brazilian version!

                                  Try,

                                  Start, Run.., cmd /k

                                  and then

                                  command /k

                                  dir (see the difference!)

                                  exit (to leave the MS-DOS command)

                                  and now

                                  exit (to leave the XP cmd)

                                  But note - not all functions are listed with command /? - they work /b, /n, /k but are not listed.
                                  "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

                                  Comment

                                  Working...
                                  X