ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Rename files in IFS

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

  • Rename files in IFS

    Anyway to do this on the IFS:

    ren *.txt *.old

    I can do

    ren file.txt file.old

    But sometimes I don't know what the name of the file is and I just need to rename the extension. I have a CL that does alot of work to get the exact name of the file so I can do the rename but that is very cumbersome work.

    Thanks in advance...

  • #2
    Re: Rename files in IFS

    this will get you started I cleaned it up the best I could
    (it does compile)
    Attached Files
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Rename files in IFS

      This will replace all of the .txt files in the current working directory with the .old extension. If you are going to use this often you might want to save this as a file and include a prompt for the directory that you want to run this on. Forgot to mention this is for QSHELL

      Code:
      for filename in *.txt
      do
      ext=`basename $filename .txt`;
      mv $filename $ext.old;
      done
      Last edited by abercrombieande; February 24, 2012, 11:28 AM.

      Comment


      • #4
        Re: Rename files in IFS

        Hi RpgKnight:

        nice article here on that very subject (the title is Mass Rename of IFS Files) :
        I find Qshell a powerful tool for manipulating IFS files, but some Qshell features make me long for my MS DOS batch file programming days. A case in point is the ability to rename files in mass. Let me show you what I mean. I want to rename the files with a .txt extension so



        Best of Luck
        GLS
        The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

        Comment


        • #5
          Re: Rename files in IFS

          I love this site .... I just had to say it.

          I've been struggling all day trying to figure out how to do this and I hop out here to post a question on how to do it and lo and behold, the answer is already here. You gotta love it....

          I have just one question though .... just learning how to do lots of cool things with the ISF and using QSHELL.... how do I tell it which folder I want to work with?

          Comment


          • #6
            Re: Rename files in IFS

            pwd = print working directory
            cd = change directory
            ls = list files in directory
            cat = view file contents

            You can always use the fully qualified path which is /. For example no matter the current directory, you could do something like ls /home/abercrombieande/java which would be like using the drive on windows c:\abercrombieande\java. If not fully qualified its relative to the current directory.

            $ pwd
            /home/
            $ cd abecrombieande/java
            $pwd /home/abercrombieande/java
            cd .. ###Goes back a directory
            $pwd
            /home/abercrombieande
            cat$ f10984
            find "${DIR}" -type f -atime +${DAYS} > /home/backups/filelist
            while read LINE
            do
            echo $LINE
            tar -rf /home/backups/${dt}.tar ${LINE} .....

            Basic commands
            http://www.tylogix.com/Articles/Expl...ies_QSHELL.htm
            Last edited by abercrombieande; March 30, 2012, 06:17 AM.

            Comment


            • #7
              Re: Rename files in IFS

              Thanks Abercrombieande! I thought that's what I needed to do but wasn't sure. Figured I play it safe and ask and save myself some headaches.

              Comment


              • #8
                Re: Rename files in IFS

                Okay - finally getting back to this and I'm having issues still. I'm attaching the program and a picture of what is in the IFS ... I just don't get it - all I want to do is change the file extension from .00x to .TIF and its telling me No such path or directory

                Why won't this work

                Click image for larger version

Name:	ScreenHunter_01 Apr. 27 16.43.jpg
Views:	1
Size:	128.3 KB
ID:	126508

                badtiffr02.PDF

                Help....

                Roxann

                How do I post my code? I have a PDF but I don't find an attachment icon....the day has been too long....sigh... what an idiot...it is there. Ha
                Last edited by NYCountryGal; April 27, 2012, 02:52 PM.

                Comment


                • #9
                  Re: Rename files in IFS

                  in the RvMailPf does the contents of the EmMail field have a / as the first character? if not you can put it in your code Path = '/' + %Trim(EmMail); if the slash isn't there it will look in the current directory of the job for the path.
                  I'm not anti-social, I just don't like people -Tommy Holden

                  Comment


                  • #10
                    Re: Rename files in IFS

                    Tom - It has the '/' in the first position.... that's what I don't understand - it should work.

                    Comment


                    • #11
                      Re: Rename files in IFS

                      What are you trying to do with FirstSpace and Period?

                      Comment


                      • #12
                        Re: Rename files in IFS

                        wild guess would be to add %TRIM() on the call to the API Rename( %TRIM(CurrentName): %TRIM(NewName)) since you aren't using varying length char fields it's passing the full length of data including blanks to the API.
                        I'm not anti-social, I just don't like people -Tommy Holden

                        Comment


                        • #13
                          Re: Rename files in IFS

                          @Abercrombieande - In my CL I do a LS command to a file and I read that file to get the names of the images that are in the folder. I'm using first space to determine if the name fills the entire field or is it smaller and period I'm using to locate the extension. It was my feeble attempt at trying to figure out why the heck it isn't working.

                          @Tom - I'll try that and let you know.

                          I'm working on three different issues today - one is easy so to speak - I'm converting a S36 program to RPGIV, the next issue is trying to clean up a user profile where the percent of private authority entries exceeds .60 on a V6R1 box and our savsecdta is taking over 3+ hours to save, and then there's this issue. Definitely makes the day go by faster....

                          Thanks

                          Comment


                          • #14
                            Re: Rename files in IFS

                            @Tom - Okay I just tried what you suggested and I am still getting the same message - No such path or directory.

                            It's going to be something so obvious and stupid...it always is....sigh

                            Comment


                            • #15
                              Re: Rename files in IFS

                              Originally posted by NYCountryGal View Post
                              @Tom - Okay I just tried what you suggested and I am still getting the same message - No such path or directory.

                              It's going to be something so obvious and stupid...it always is....sigh
                              apparently it's not that obvious...stupid maybe but we all do that
                              I'm not anti-social, I just don't like people -Tommy Holden

                              Comment

                              Working...
                              X