.st0{fill:#FFFFFF;}

How to rename IFS Files 

 July 3, 2019

By  NickLitten

Colleague asked me this question just a minute ago – as he said “its obvious when you know how but not when you dont”

Simply use the IBM i RNM command:

How to rename IFS Files 1
how to rename IFS file

Personally, I find this command syntax a little annoying: fully qualifying the FROM string and then just using the unqualified NEW file name in the TO string.

But it works anyway:

How to rename IFS Files 2

There is also a nice article over at ITJUNGLE detailing how to do bulk file renames. The article is ten year sold so just in case it vanishes here it 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 that they have a .csv extension instead. I only want to rename .txt files, and I only want to rename the files in a certain directory. In MS DOS, I would have used a rename command with wildcards in both arguments.

ren *.txt *.csv

Try the same thing in Qshell and you get an error.

mv *.txt *.csv
mv: 001-0085 Too many arguments specified on command.
mv: 001-3017 usage:
    mv [-f | -i] source_file target_file
    mv [-f | -i] source_file ... target_dir

Please don’t tell me that I have no choice but to rename the files one by one.

–Chuck

The Unix shells predate MS DOS, Chuck, so Microsoft had the advantage of circumventing some of the Unix shells’ less desirable features. I don’t know if they purposely did so or not.

But to answer your question, you can rename files in bulk. Use the following three-line script.

for file in *.txt; do mv "$file" "$(basename $file txt)csv"; done

Here’s how it works:

The “for” loop runs once for each file that has a .txt extension. The basename utility returns the name of a file without the trailing txt extension. That is, “customer.txt” becomes “customer.”. Yes, the period is not stripped off. Qshell appends “csv” to the name.customer.csv. and passes it to the mv command, which interprets it as the second parameter.

mv customer.txt customer.csv

The mv renames the file.

If file names can have blanks in them, use this command sequence instead.

for file in *.txt; do base=$(basename "$file" txt); mv "$file" "$base"csv; done

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

I’m always looking for awesome input, feedback and critique!

>