Solved Batch File Script to Switch Filenames

January 14, 2013 at 13:26:01
Specs: Windows 7
I know this sounds so simple and maybe my brain is just not there today.

How could I switch file names between two files.

formatted.txt - Filename never changes
datafeed.txt - Filename changes

Essentially I'm trying to take formatted.txt file that another program formats and give it the datafeed.txt filename. But datafeed.txt could have any filename because its generated by system.

Simply switching filenames.

See More: Batch File Script to Switch Filenames

Report •

January 14, 2013 at 17:15:24
I can't really understand the problem from your description. It sounds like you just want to rename or copy formatted.txt to this other name, but that can't be it because it's too simple. The "other" name, being variable, you've got to have a way to come up with it - some criteria. Maybe you can elaborate and/or give a more concrete example?
Apologies for replying without giving an answer...

Report •

January 14, 2013 at 17:33:24
Sorry to sound confusing but I'm new to batch programming.

I basically want to swap file names.

Report •

January 14, 2013 at 18:02:03
✔ Best Answer
Well, maybe start with this:
@echo off
:: there should be a way to find this without prompting for it... date+time, size,
:: location, some content (if text), etc.
set /p x=enter the system-generated filename:
:: create a temp filename that hopefully does not exist
:: or just try something like #hold...
set temp=%date%%time%
set temp=hold%temp:~4%
:: safety, if you think it's needed: if exist %temp% echo FAILED
move /y formatted.txt %temp%
ren %x% formatted.txt
ren %temp% formatted.txt
echo done.
::==== end
you could also move the file to some other directory, (for temporary storage), instead of renaming it, then move it back to the other filename.

Report •
Related Solutions

Ask Question