Tech Support Guy banner

Cycle the names of several text files

2341 Views 12 Replies 3 Participants Last post by  DocBenOrdway
I want to cycle the names of several text files. I haven't done anything like this in over 25 years.

Example:
Start with - base.tax
2.txt
3.txt

Theory -
@Echo off
Rename 3.txt tmp.txt
Rename 2.txt 3.txt
Rename base.txt 2.txt
Rename tmp.txt base.txt
Delete tmp.txt

This should be ready to go again and make the original 2.txt the new base.txt.

The plan is to schedule the batch file to run (at a time & repeat yet to be determined) with Windows Task Scheduler.

I am currently on Windows 10 but will probably get smart and go back to Windows 8.1 later this week.
Status
Not open for further replies.
1 - 13 of 13 Posts
It helps to describe the task fully to avoid misunderstandings, and you may get a far better solution.
It helps to describe the task fully to avoid misunderstandings, and you may get a far better solution.
Consider a screensaver-type app. I want to display a different "set" of text messages to the network each day. The number of "sets" could very with time. My example is simplified down to 3 "sets".
A random text message can be taken from a single file - the type of message will determine if that's a useful way to do it.

Or do you want to cycle a set of messages in a single order?
Cycle a set of messages in a single order. Then a different set (say the next day). Then a different set (say the next day). Etc.
So you're planning on having several sets of files?

With a good description I am fairly certain it can all be contained with one batch file.
But this is what you asked, I think. It's untested.

Code:
ren base.txt base.tmp
ren 2.txt base.txt
ren 3.txt 2.txt
ren base.tmp 3.txt
Thank you. That confirms what I thought.

I tested it, and after a few false starts, it does work.

I'm now testing it with Task Scheduler.

Thank you.
Thank you. That confirms what I thought.

I tested it, and after a few false starts, it does work.

I'm now testing it with Task Scheduler.

Thank you.
Well that didn't go so well and I thought that would be the easy part.

I successfully tested the .bat file.

I created a shortcut to test run the .bat file and it worked.

I set Task Scheduler to run the .bat file. Failure. History says the scheduled task ran. It did not.

I set Task Scheduler to run (several times) at 10 min. in the future. I see what appears to be the .bat file running but it did not cycle the files.

Is there a "but" hidden in Task Scheduler?
It did run, but it did the old "switch to system32 folder" trick.

The current folder isn't what you think it is - you have to change the folder as the first command, or use explicit paths in the rename command.
How is the scheduled task configured?
General
Run only when user is logged on [Note: Logged on 24/7]

Triggers
Daily
Start: 1/29/2016 4:00:00 AM
Recur every: 1 days
Advanced settings
Enabled

Actions
Start a program: "C:\Utilities\Screensavers\Marquee Plus\Cycle Sayings.bat"
[Note: Also tried "C:\Cycle_Sayings.bat" with the 3 text files in the same location]

Conditions
Start the task only if the computer is in AC power
Stop if the computer switches to battery power
[Note: Desktop with UPS]

Settings
Allow tasks to be run on demand
Run tasks as soon as possible after a scheduled start is missed
Stop the task if it runs longer than: 3 days
If the running task does not end when requested, force it to stop

History
Number of events: 43
[Note: The Task/Action is listed as completed: 7 times - that includes my tests]
See less See more
The current folder isn't what you think it is - you have to change the folder as the first command, or use explicit paths in the rename command.
Did you understand this?
My apologizes, I did not get notice of your 2:09 AM posting. I did get the 1:41 PM post and that got this old head remembering more about .bat files that I wrote in the 1980s.

I specified (cd) the path and ran a test. It appears to work so I have reset the time to 4 AM and We'll see what happens tomorrow.

Thank you for all your help with something that should have been simpler for me.
1 - 13 of 13 Posts
Status
Not open for further replies.
Top