There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
DOS Batch-add a string to the front of records on a file.


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
jglong3's Avatar
Senior Member with 124 posts.
 
Join Date: Jul 2003
17-May-2005, 02:13 PM #1
DOS Batch-add a string to the front of records on a file.
Hello TSG Development----

THANKS for your advise, time, and help!!!!

It's been a long time since I have done DOS Batch file development and I cannot remember if the following can even be done with a DOS BATCH command line.

The problem solution is probably simple:
What DOS command line logic is required to prefix a string to records on a file.
And, this is where my rememberance of DOS command line falls short----How to get the string, any string added to the front of each record on a filename.txt file.


DETAILS:

The concept is to RENAME files using a pattern matching type technique, using the full filename (>8.3), a filename that contains a SPACE character as part of the filename, and in batch.

The following processes have been reviewed and many work as required, but the ones that do work as required do not allow full batch execution of the process to rename the files as required.

REVIEWED RENAMERS
-4A RENAME
ANT RENAMER
AF5 Rename
ARen
BATCH RENAMER
BATCH FILE
RENAMER
BETTER FILE RENAMER
BULK FILE RENAMER
D-FILEMU
D3v2
EXIFREN
FILE RENAMER(PC or MAC)
FREN2005
LUPAS RENAME 2000
RENAME-IT
RENAMEALL
RENAMIT
RENAMESTAR
SIREN
SPACE-B-GONE
WITRENAMER
Tried using the following CHOICE command to create a bat file to be executed recusivley with the full filename, plus a SPACE in the filename. However, using the following CHOICE command on a filename that contains a SPACE will create the output file, but the CHOICE command never returns to execute the .b.bat. And, it is interesting that the characters of the filename that are after the SPACE are first on the output file with no comma delimiters and the leading characters up to the SPACE are last on the output file and are delimited with commas, with the contents of the %0 argument in the middle.

> .\b.bat echo;;|choice/c?%filename%; %0;
.b.bat

Using the above CHOICE command on a full filename with no SPACE will return to execute the .b.bat file as expected. Plus the b.bat file contains the characters of the full filename delimited with commas as expected and the %0 is on the front of the comma delimited full filename string.
Also, using the FOR IN (SET),,,, to load the above %filename% only provided the 8.3 format.

I am now working with the following command:
ATTRIB > Fullfilename.txt
The records created to Fullfilename.txt by ATTRIB contains the required FULL FILENAME (>8.3 convention), while using the FOR %%X IN (SET) DO,,, provides only the 8.3 convention.

The command line ATTRIB > Fullfilname.txt creates the following records to Fullfilename.txt including the SPACE in the Fullfilename:
Note: The SPACE character is between the } and ( characters as in
,,,,04-19} (2),,,,,,etc.
A {2005-~2.WAV C:\jlong\filere~1\d-filemu\{2005-04-19} (2).abc
A {2005-~3.WAV C:\jlong\filere~1\d-filemu\{2005-04-19} (3).abc
A {2005-~4.WAV C:\jlong\filere~1\d-filemu\{2005-04-19} (4).abc

What I would like to create to the Fullfilename.txt is the following or anything that is similar, or any command line sequence that would output this to some file executed recursivley, until all records (files) are processed, etc.:

RMSPACE A {2005-~2.WAV C:\jlong\filere~1\d-filemu\{2005-04-19} (2).abc
RMSPACE A {2005-~3.WAV C:\jlong\filere~1\d-filemu\{2005-04-19} (3).abc
RMSPACE A {2005-~4.WAV C:\jlong\filere~1\d-filemu\{2005-04-19} (4).abc

The SPACE(s) in the above created Fullfilename.txt act as a delimiter in a DOS call sequence and thus logic in DOS can be used to rebuild the filename (removing the SPACE). For example, using the records above by combining the %3 and the %4 arguments. And, once the file is renamed to remove the SPACE the CHOICE command can be used on the new file name to put the comma delimeters between each character.

I have tried to modify the
ATTRIB>Fullfilename.txt
using the
FOR %%x IN (SET) DO,,,,
but, I cannot get the string "CALL RMSPACE " added to the front of each record created to Fullfilename.txt.

If this is possible using DOS command line, the above filename Fullfilename.txt will be changed to a .bat file convention and then executed.

Further logic can then be used to remove selectable characters from the comma seperated filename to RENAME the original filename to something like the following:
0504192.abc
0504193.abc
0504194.abc

Maybe, it cannot be done at all in a DOS Command line batch file(????),,,, I just cannot remember!!! ;-|

THANKS for your time, help, and advise!!!!!

Jerry
jglong3's Avatar
Senior Member with 124 posts.
 
Join Date: Jul 2003
18-May-2005, 02:23 PM #2
Hello TSG Development,,,,

The original description has been answered but with a CALL to a .exe.
Any advise related to the original description using only DOS Command line to modify and add strings to the front of records on a text file would be GREAT!---That is,,,,,even if this is possible using only DOS Commands.

A few hours after the description was entered google was used with more search criteria related to this situation. A routine named EDIFIC.EXE was found. This routine can be called from batch and has a input file it reads that the user must insert EDIFIC commands. The set of commands documented are HUGE and allows:
REPLACESTRING "xxxxxxx" with "YYYYYYYY"
This provides the ability to modify records on the Fullfilename.txt file as described:
add the string CALL REPSPACE to the front of each record created by ATTRIB > Fullfilename.txt
The file created by ATTRIB has been renamed in the code with the .BAT extension and is executed with the desired results.

FYI: The link to the site that provides this routine is the following:
http://www.eunet.bg/simtel.net/msdos/fileutil-pre.html[/url]
Also, there was another site that was found that looks interesting, but it has not been used at this time:
http://home.att.net/~short.stop/freesoft/filutil1.htm[/url]
THANKS for your time, help, and advise!!!!

Jerry
MacFromOK's Avatar
Senior Member with 1,947 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
18-May-2005, 10:31 PM #3
Not sure exactly what you're doing here, but to "add a string to the front of records on a file", you should be able to "echo" the string to a temp file, copy the original to a temp file, then use "copy" to combine the temps to the original file. Something like this:

echo new data string > temp1.txt
copy original.txt temp2.txt
copy temp1.txt+temp2.txt original.txt


Hope this helps, maybe ya can be more specific on your question without telling us everything that doesn't work.

Cheers, Mac
__________________
MacFromOK : PC User
Do I have all the answers?
I don't even have all the questions!

____________________________________________________________
jglong3's Avatar
Senior Member with 124 posts.
 
Join Date: Jul 2003
20-May-2005, 05:00 PM #4
Hello Mac,,,,

OK and THANKS for the REPLY!!!

OOOPPPS,,,,sorry for the misleading description.....

The situation for example has the followng filenames in a directory:

{2005-04-19} (2).wav
{2005-04-19} (3).wav
{2005-04-29} (8).wav
And, need to work with the long file names. The "FOR %x in (SET) do,,,,"
only gives the 8.3 filename format.

The long file name can be created to a file with either DIR or ATTRIB. I selected the followng command line to get the long filenames to a file:
ATTRIB *.wav* > Filename.bat
and the above command line produces the following to the Filename.bat file:

A {2005-~2.WAV C:\jlong\{2005-04-19} (2).wav
A {2005-~3.WAV C:\jlong\{2005-04-19} (3).wav
A {2005-~4.WAV C:\jlong\{2005-04-29} (8).wav
What I would like to understand is how can each record be modified in filename.bat using, if possible, only DOS command line code to produce the following:

Call RemSpace A {2005-~2.WAV C:\jlong\{2005-04-19} (2).wav
Call RemSpace A {2005-~3.WAV C:\jlong\{2005-04-19} (3).wav
Call RemSpace A {2005-~4.WAV C:\jlong\{2005-04-29} (8).wav

I have found a way to do this but it requires a call to a .exe file,,,, I would like to do this in DOS Command Line code if possible!!!

THANKS for your time, help, and advise!!!!
Jerry
MacFromOK's Avatar
Senior Member with 1,947 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
20-May-2005, 10:54 PM #5
Ah I see. I don't know of a way to edit one line of a file with batch commands, other than by using some type of utility like you apparently are doing.

Cheers, Mac
jglong3's Avatar
Senior Member with 124 posts.
 
Join Date: Jul 2003
23-May-2005, 01:25 PM #6
Hello MACfromOK,,,

OK,,,and THANKS for the reply and Info.!!!

It was a long time ago (pre Windows) that work was done on DOS Command Line and if my remeberence is correct that is what we had to do then,,,,Fortran, C, C++, Basic, etc. I was not sure if DOS/Windows now days had a direct method to read records from a text file(???). I thought that even by W95 or w98 there might now be a direct DOS method to process records from a text file.


OH,,,Well-----and thanks for the confirmation and your time!!!


Have a nice week!!!!
Jerry

Last edited by jglong3 : 23-May-2005 01:33 PM.
ender21014's Avatar
Junior Member with 1 posts.
 
Join Date: Jul 2005
Experience: Advanced
15-Jul-2005, 08:08 PM #7
This might help. I've tested this on win xp only because I just now figured it out and found your post while searching for my answers.

You can parse text files using the "for /f" command use for /? for details

Or you can make the batch file use quotes properly, I was having a problem with a "for /r" loop to delete cookies from every user in the documents and settings folder. It kept saying The system cannot find the path specified. I finally figured out where to put the quotes in the batch file so it would work right. I had to make sure the starting path had quotes around it and the parameter of the delete command had quotes around it. This is what worked

for /r "c:\Documents and Settings\" %%f IN (Cookies) DO del "%%f\*"


Hope this helps.
jglong3's Avatar
Senior Member with 124 posts.
 
Join Date: Jul 2003
18-Jul-2005, 03:04 PM #8
Hello ender21014 ,,,,

OK,,,and THANKS for the INFO!!!!

The system I am working with is W95 and 98,,,,,,and the last I remember,,,(not next to a 95 or 98 now to see),,,,the /f qualifier is not available in the FOR on these systems,,,also the FOR only procuces the 8.3 filename character convention on thse systems.

And, for the W95 and 98 Operating Systems I have resolved to use the DOS command ATTRIB to create a file that contains the full filename convention (>8.3 characters) for all files . And, EDIFIC.EXE mentioned above to modify the front of each record (line) in the full filename file. I am suprised that the results only takes about 2 seconds to rename about 50 original file names with a SPACE in the filename to filenames without the SPACE.

However,,,,it is great to know the /f qualifier has evolved at some point.!!!!

THANKS for your time, help, and advise!!!!

Jerry
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:15 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.