Solved

txt to csv (vbs)

Posted on 2013-10-30
3
805 Views
Last Modified: 2013-10-30
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
Comment
Question by:W.E.B
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
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

REM Return to original directory
popd

Open in new window

~bp
0
 

Author Closing Comment

by:W.E.B
ID: 39611202
Thank you.
Works like a charm.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39611209
Welcome.

~bp
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
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…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question