Solved Batch file help needed

December 18, 2013 at 07:24:14
Specs: Windows XP
I need the following batch file code added to so the original file is copied before being modified as shown below.The batch file sorts out text file contents alphabetically , a at top , z at bottom.
The way it is now it leaves the original untouched and unnamed and makes a copy of original but is renamed.
@echo off
sort original.txt /o modified-original.txt
echo: FILE HAS BEEN SORTED ALPHABETICALLY TO AN OUTPUT FILE
echo: THE ORIGINAL HAS BEEN LEFT ALONE
pause

Thanks!
I appreciate your help.
Val


See More: Batch file help needed

Report •

#1
December 19, 2013 at 11:41:25
Your post is a bit vague. I don't see a reason to copy the original in your example. You could easily by using "copy", however the way the set of commands that you show seem to work (as most batch reads do) is that it reads from the original and then sorts and directs output to the second file. Theoretically, your original file goes unedited/unchanged. IF you are trying to make it so that you can save the new file with the original files name, you could rename the file.

@echo off
::using the format 5662.bat <filename>
rename %1 m%1
sort m%1 /o %1
echo: FILE HAS BEEN SORTED ALPHABETICALLY TO AN OUTPUT FILE
echo: THE ORIGINAL HAS BEEN RENAMED m%1
echo CURRENT SORTED FILE IS %1
::proof of sort, theoretically.
type %1

::mike


Report •

#2
December 19, 2013 at 15:44:10
Yo mikelinus...
I want a backup copy of "original.txt" first.
Then I want to sort the original alphabetically with it's original name "original.txt" in this case.
The code you gave me didn't work at all so I modified it ( I am guessing I was supposed to anyway ).
I tried this code ( I am real new to this ) and it don't work.
Something about a syntax error.

@echo off
rename %1 original.txt m%1 original.txt
sort m%1 /o %1
echo: FILE HAS BEEN SORTED ALPHABETICALLY TO AN OUTPUT FILE
echo: THE ORIGINAL HAS BEEN RENAMED m%1
echo CURRENT SORTED FILE IS %1
type %1
pause

Thanks again!
Val


Report •

#3
December 19, 2013 at 16:59:50
✔ Best Answer
The intention was to type the name of the batch a space and the name of the file, or drag and drop( I assumed that you had more than one file.

here is an update for only one

echo off
::5662.bat
copy original.txt backuporiginal.txt
sort original.txt /o sortoriginal.txt
echo: FILE HAS BEEN SORTED ALPHABETICALLY TO AN OUTPUT FILE
echo: THE ORIGINAL HAS not been touched
echo a backup of the backup is named backuporiginal.txt
::proof of sort, theoretically.

type sortoriginal.txt
echo rename sortoriginal.txt original.txt
::remove echo after testing
::mike

message edited by mikelinus


Report •

Related Solutions

#4
December 20, 2013 at 07:22:02
I modified your file a tad shown below and it worked great for 1 file.

@echo off
copy original.txt backuporiginal.txt
sort original.txt /o original.txt
echo: A BACKUP OF THE ORIGINAL SAVED AS backuporiginal.txt
echo: THE ORIGINAL HAS BEEN SORTED ALPHABETICALLY
pause
:: I put the pause in so I could see if any errors popped up
:: none did

Thanks!

Now I need help on sorting more than 1 text file in the same folder.
I looked at your first answer and I don't understand how to make that work.
I tried the code and it won't work as shown to do multiple files even with the drag and drop you mentioned.If the code is correct please tell me what I did wrong.I am really new to batch stuff , so please bear with me.

I tried making my own batch that would sort 3 test files alphabetically at once and I got the error listed
below this batch test file.

@echo off
copy "*".txt backup"*".txt
sort "*".txt /o "*".txt
echo: A BACKUP OF ALL ORIGINALS SAVED with backup predix
echo: ALL ORIGINAL HAVE BEEN SORTED ALPHABETICALLY
pause
:: I put the pause in so I could see if any errors popped up
:: The entire cmd box shown below

2original.txt
3original.txt
backupnal.txt
The file cannot be copied onto itself.
2 file(s) copied.
*.txtThe filename, directory name, or volume label syntax is incorrect.
A BACKUP OF ALL ORIGINALS SAVED with backup predix
ALL ORIGINAL HAVE BEEN SORTED ALPHABETICALLY
Press any key to continue . . .

How do I make a batch file to do a bunch of txt files in the same folder?

Thanks!
Val


Report •

Ask Question