Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file

Status
Not open for further replies.

RSHH

IS-IT--Management
Aug 16, 2002
19
0
0
US
I need to create a batch file that will open a text file, find an entry, replace it and then close the file.

Any ideas?

Cant use VB as it needs to be compatable with as many machine as possible.


Thanks in advance
 
You will have a similar problem with batchfiles - each version of windows uses a different version of DOS. Meaning some commands that were available in ver 6.2 of dos are no longer available and vice verser some of the new features were not available back then.

However that being said personally I cannot think of any dos commands that check for specific text in a file.

The closest you will get is the FC command in dos that checks two or more files and the displays the differences.

Hope this helps???


Greg Palmer

----------------------------------------
Any feed back is appreciated.
 
You could also use Visual Basic Scrip - I'm not sure but think the microsoft has added VB Script compatibility into all versions of Windows from 95 upwards.

Add the following into a text file and save is as filecheck.vbs (name can be anything but must end .vbs)

Set FSO=CreateObject("Scripting.FileSystemObject")
Set TF=FSO.OpenTextFile("c:\test.txt",1) ' 1=ForReading
inp=TF.ReadAll
out=Replace(inp,"search text","Replace text")
TF.close
Set TF=FSO.CreateTextFile("c:\test.txt",True)
TF.Writeline out
TF.Close

Change the two file names to the name of your file, change the "search text" to what ever you are searching for and "replace text" to what you want to change it to.

Then just double click on the vbs file and it should do the work for you



Greg Palmer

----------------------------------------
Any feed back is appreciated.
 
Could something like this be used for distributing a FrontEnd of an Access 97 database? Currently, I have shortcuts pasted into an e-mail instructing the user to:
1) Open Shortcut A
2) Copy the file(s)
3) Open Shortcut B
4) Paste the files
5) Cut the supplied shortcut C
6) Paste C onto desktop


Could the above be shrunk to a vbs file then the file sent out? That way all the user would have to do is to double click the file and the copy/Paste....Cut/Paste would be done automatically.
If not, could does anyone have any ideas on how to create such a batch file to simply copy files from N:\temp\cbu\eber.mde , paste them to C:\eber.mde Also, if possible how to cut a shortcut from N:\ and paste directly to the desktop?



Thank you for any and all help,

PBrown
 
Hi pbrown2

You would defently beable to do this in VBScript. VBScript will work on any computer with I.E. Installed on it.


Here is some sample code to help you.


Dim fso, file1,file2
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")

fso.CopyFile (file1,file2)
fso.DeleteFile(file1,file2)
fso.MoveFile file1,file1

WshShell.SpecialFolders("AllUsersdesktop") 'returns the all users desktop folder

WshShell.SpecialFolders("desktop")' returns the current users desktop folder

For further information on VBScripting go to
Hope this helps.

Hugh
 
RSHH,

If all the machines are running some variant of Windows 95 (or NT), I'm sure a simple VB app would work on all of them, assuming it was properly set up.

Another option would be to write a dos app in something like QB 4.5 (you can find this for download, if you don't have it - check out the Qbasic forum). I still use that to make a quick program like you're talking about. If that would work and you want to post details (or your email address), I could probably write something for you to try.

If you're talking about something working with Windows, Unix, Apple, Dos, or anything else, I don't know what you could do.

 
YOu could also write a small batch, should be good enough for all current Windows versions:
save it as e.g. install.bat in N:\temp\cbu
copy eber.mde C:\eber.mde

or like this:
md C:\DB
copy *.* c:\DB

if all files to copy are in one folder.

Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
I tried this for one set of files and it works great! However, when I try it under a different location it does not work. I think it has to do that one path is:
N:\Temp\cbu
the other is
I:\Paul\Capital Budget

Is there away to format the batch file to beable to read to a folder that has a "space" in the folder name? as in Capital Budget

I have tried to put a _ but it did not work...

Thank you for any and all help,

PBrown
 
Yepp,

you have to enclose the path in brackets.

For the network letter issue:
try using the UNC path ( \\servername\sharename\...)
instead.

There is also a dos command called "net use", which you could take advantage of in this batch...

MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
I tried:
*Wrap text wrapped it**

copy (I:\Paul\Capital Budget\Capital_Budget.mde) (C:\Capital_Budget.mde)

But it did not work.....

Also, by the means I have been using upto this point, is there away to get a shortcut to copy then paste to the desktop.
Tried:
copy N:\Temp\cbu\shortcut.lnk c:\desktop

I believe the problem is that since we are on a network, each persons desktop settings is saved under:
C:\Winnt\Profiles\**USERID**\Desktop
This way, no matter what computer we log into our settings never change.

Is there away to have the userID to autmatically fill in or a way to bypass this???

As for "Net Use" I am unfamilar... would this help with the desktop needs as well???


Thank you for any and all help,

PBrown
 
Did i say brackets? Oh my English is getting worse...[blush]
I meant quotes:
copy "I:\Paul\Capital Budget\Capital_Budget.mde" "C:\Capital_Budget.mde"

Concerning net use:

You can always open the command shell and type something like:
net use /?
You will get help on the use of the respective command.
In this case
net use Z: \\servername\sharename
should do it. I chose "Z:" because you have to make sure, that the letter is not used by another network drive.

MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
Well, I had better stay away from the NetUse..... Simply because I have access to network drives A - W and I know there are a few drives in which I do not have access to. I do know that everyone with network access does have access to N: therefore I think I should be safe.

Do you have any ideas as to how to get the shortcut to paste to the desktop?
I know in Access I have used =Environ("UserName") many time to get the username. Is there something similar that can be used to get the user name so that the **USERNAME** for the below patch can be filled in?
c:\winnt\profiles\**USERNAME**\desktop

Or is there away to have an input box appear for them to input their username?
Worst case, I will simply have to include a shortcut in the e-mail for them to cut and paste onto their desktop. However, I would like to avoid this...

Now, in terms of "appearance", since I know management will ask... Since it takes a few moments for the copy file from the batch file to complete, is there away to have it run "invisibly"? Then simply activate the shortcut to open the file when completed?

This way the user cuts and pastes the shortcut (if it can not be written into the batch file), next double clicks the batch file I will attach to the e-mail, choose "Open It" and the next thing they see (after a small coping time) is the database.

Thank you for any and all help,

PBrown
 
Unfortunately, I am not sure of how to let a batch file run invisibly.
Since my files are only a few megs (5), it's a matter of 2 seconds...
You can try with
echo off
in the beginning of the batch file.
Concerning the shortcut: I know, there must be some environment variable but I have no idea... :-(



Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
Will try echo off..

Another idea for the shortcut....
Is there any way in access to have the database, when it is opened to make a shortcut to itself on the desktop, if one is not already in existance???

Thank you for any and all help,

PBrown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top