Solved

# txt to csv (vbs)

Posted on 2013-10-30
800 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
• 2

LVL 53

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 53

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

### Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…