File extension change from .txt to .vbs

I am working on a project to change .txt files to .vbs files without manually changing the extension... How would I change the file extension using c++ so that I could just input a file name and it would get that .txt file and change it to a .vbs file?
You can rename files using the std::rename function.

http://www.cplusplus.com/reference/cstdio/rename/
It's a pain. Use the command processor:

for %F in (*.txt) do ren %F %~nF.vbs


If you want, you can put it in a batch file:

chext.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@echo off
if %1.==. goto help
if %2.==. goto help
goto :run

:help
echo. chext *EXT1 EXT2
echo. Changes all files with EXT1 to use EXT2.
echo. For example, to change all .txt files to .vbs files
echo.   chext *.txt .vbs
echo.
goto :end

:run
for %%F in (%1) do ren %%F %%~nF%2

:end

If you really want to do it with C++, you should check out Boost.Filesystem.

Hope this helps.
I'm getting errors when I'm using you method, Duoas, and I don't really understand the code... Sorry I'm kind of a beginner.
It's Windows Batch script, not C++. What errors are you getting?
Topic archived. No new replies allowed.