Announcement

Collapse
No announcement yet.

RENAME file

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

  • RENAME file

    Suppose I have:
    FileOut3$ = "E:\LGS\States\New\" & trim$(StateArray$(StateCount,1)) & ".Dat"
    FileTemp$= "E:\LGS\States\New\" & trim$(StateArray$(StateCount,1)) & ".TMP"


    (Let's say FileOut3$ = AK.Dat)

    I am trying to rename AK.Dat to AK.TMP.


    I tried saying
    SHELL " ren FileOut3$ FileTemp$"

    I want the AK.Dat file renamed to AK.TMP

    But I get this error:
    Duplicate file name or file not found.

    How should I rename files from inside a DOS Powerbasic program please?

    Thanks.

    Robert

  • #2
    try NAME

    look up NAME

    Name filespec1 AS filespec2

    regards, Ian.
    :) IRC :)

    Comment


    • #3
      Keep doing a DIR$ for AK.TMP.

      Then, if found, delete the AK.TMP file or modify the output file name to AK.T[1], AK.t[2], etc.
      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


      • #4
        Another way to make sure your old backup doesn't longer exist is to open it as Binary, Close it, and then Kill it. This way you are not going to get an error trying to give a file an existing name, nor an error trying to KILL a non existent file.

        Open FileTemp$ for Binary as #1
        Close 1 'Now the file actually exists
        KILL FileTemp$ 'Now the file doesn't exist
        Name FileOut3$ as FileTemp$

        Regards,

        Comment


        • #5
          BINARY !!!!

          That's the right word. Would you believe a teacher (Not a powerbasic teacher) told us the way to do it was:

          Open FileTemp$ for BIN as #1


          Which of course never worked for me. (Yes, I realize it is not Powerbasic's fault, but geeze, I believed this teacher!) If the teacher were alive today, I would take my laptop to his house and show him the correct format.
          Thanks, Manual. Thanks, everyone!

          Robert

          Comment


          • #6
            BINARY? BIN?

            Real Men...
            Code:
               OPEN "B", #1, filetmps$
            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              BTW, the same technique can be used to verify whether a file exists.

              Code:
               
              Open "B", #1, Filespec$    'This notation is not accepted by PBCC, so do not get acustomed if you plan to move.
              LF&=LOF(1)
              Close 1
              If LF&>0 Then
               Print Filespec$;" exists and it's size is ";LF&
              Else
               Kill Filespec$
               Print Filespc$;" doesn't exist"
              End If
              Last edited by Manuel Valdes; 17 Oct 2009, 06:08 PM.

              Comment


              • #8
                Err... don't? Just don't. It is never appropriate to open a file just to detect whether it exists. Those are two entirely separate kinds of operations. I'm not going to get into a long story of doom about how confusing the two will cause your dogs to be cats, and your cats, potatoes, but you really don't want to go there.

                Comment


                • #9
                  OK Tom, then is not a technique but only a trick, and certainly is not wise to use it on files others than the ones your program created. I have used it only that way.

                  Best regards,
                  Last edited by Manuel Valdes; 17 Oct 2009, 06:39 PM.

                  Comment


                  • #10
                    Originally posted by Manuel Valdes View Post
                    Another way to make sure your old backup doesn't longer exist is to open it as Binary, Close it, and then Kill it.
                    Usually I just KILL the file then ERRCLEAR to get rid of any potential error state
                    Real programmers use a magnetized needle and a steady hand

                    Comment


                    • #11
                      There is an Exist function that ships with PB35. If memory serves me correctly you can find it in either DOSUNIT.bas or DIRUNIT.bas (in the EXAMPLES folder).
                      Scott Slater
                      Summit Computer Networks, Inc.
                      www.summitcn.com

                      Comment


                      • #12
                        I don't understand what the bru-ha-ha is.

                        te$ = dir$(path$ + filename.ext)
                        if te$ <> "" then kill path$ + filename.ext

                        A short little two-liner that works.
                        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


                        • #13
                          >then is not a technique but only a trick,

                          It's a trick when someone else does it.

                          It's a technique when you do it.
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            try

                            SHELL " ren " + FileOut3$ + " " + FileTemp$

                            Comment

                            Working...
                            X