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:
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:
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:
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.
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
IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd 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 in the words of the most interesting man in the world: Stay thirsty my friend.
How to copy IBM i IFS folder
How to rename Fresche (BCD) Presto Library – XL_PRESTO
How to move IFS from *SYSBAS into iASP (Independent ASP)
IFS File system error occurred. Error number 3021?
Using TURNOVER in an IBM i iASP Environment
Preparing to implement IBM i iASP (Independent Auxiliary Storage Pool)
Update IBM i IFS Objects Data Change Timestamp
How to read a Data Area (*DTAARA) using IBM i SQL
How to update RDi – Rational Developer for IBM ‘i’ Programmers