Solved

# txt to csv (vbs)

Posted on 2013-10-30
812 Views
Hello,
is there any .vbs or .bat (double clicking), that would change the extensions of files in a certain folder (C:\Users\Wassim.QA-DOMAIN\Desktop\Orders Invoices)
from .txt to .csv when the file name starts with
116
1023
10052
7351
1645

from .csv to .txt when the file name starts with
451
4645
7714

Sometimes some of the files do not exist.

Any help is appreciated.
Thanks,
0
Question by:W.E.B
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 54

Accepted Solution

Bill Prew earned 250 total points
ID: 39611192
Here's a small BAT file that will do the job, just adjust the folder name near the top.

@echo off

REM Define location of files, and prefixes for file names to rename
set BaseDir=c:\ee\ee28280865\files
set txt2csv=116,1023,10052,7351,1645
set csv2txt=451,4645,7714

REM Move to directory where files are
pushd "%BaseDir%"

REM Rename TXT files to CSV
for %%A in (%txt2csv%) do ren "%%A*.txt" "*.csv" >NUL 2>&1

REM Rename CSV files to TXT
for %%A in (%csv2txt%) do ren "%%A*.csv" "*.txt" >NUL 2>&1

popd

~bp
0

Author Closing Comment

ID: 39611202
Thank you.
Works like a charm.
0

LVL 54

Expert Comment

ID: 39611209
Welcome.

~bp
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
###### Suggested Courses
Course of the Month2 days, 23 hours left to enroll