Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Write a batch command in DOS

Posted on 2010-11-30
12
Medium Priority
?
482 Views
Last Modified: 2012-08-13
Hi Experts -

I need to write a batch command for the below DOS commands:

pushd \\jassrv02\jas-fp$\documents
DIR /B /O:N > filenames.txt



I am not a DOS expert at all so could someone show me how to do this?  I know that I open Notepad and save it as an .exe file and I know if I type in the above lines in a command prompt I get the information I need but I am not sure how to write the batch command.  Any assistance provided would be appreciated.

Thanks
0
Comment
Question by:mtrussell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 34241393
A batch file is basically a collection of commands - and you DO NOT save it as a .EXE - you save it as a .CMD or .BAT.  

For example, save those two commands in text file called "mybatch.cmd" and then simply type mybatch to run it.
0
 
LVL 22

Expert Comment

by:Christopher McKay
ID: 34241437
To create a batch file, open notepad, type the commands you want, then save as a ".bat" file.

Now, specifically, what are you attempting to do with the above commands?

It appears you're attempting to get a list of all the filenames in "\\jassrv02\jas-fp$\documents" in a file called "Filenames.txt"

If this is what you're attempting to accomplish, how about trying this command:

Dir /B /O:N "\\jassrv02\jas-fp$\documents" >>filenames.txt




Hope this helps!

:o)

Bartender_1
0
 

Author Comment

by:mtrussell
ID: 34241503
Thanks!  The reason I can't do the second suggested command is I have to force DOS to find the network... ok last question what line do I put in this so the command window doesn't pop-up, is there a way to run this in the background?
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 57

Expert Comment

by:Bill Prew
ID: 34241510
Just to add a bit more.  You may not even need the PUSHD, since the following should work:

DIR /B /O:N \\jassrv02\jas-fp$\documents > \\jassrv02\jas-fp$\documents\filenames.txt 

Open in new window

If you do need to do the PUSHD for some reason then it is good practice to "undo" the push when you are done working in that directory with a POPD.  So that would look like:

pushd \\jassrv02\jas-fp$\documents
DIR /B /O:N > filenames.txt 
popd

Open in new window

Most people like to suppress the display of each command in a BAT file from displaying, and that can be done with an ECHO OFF command.  Adding an @ at the front of that line will even suppress it from displaying.  So the script could then look like:

@echo off
pushd \\jassrv02\jas-fp$\documents
DIR /B /O:N > filenames.txt 
popd

Open in new window

Lastly, if you wanted for clarity sake, you can assign paths of filenames to variables in the script to make it more readable, more maintainable, or save some typing.  So something like this will work (notice it's a good idea to enclose filenames in double quotes just in case they ever contain spaces):

@echo off
set ServerFolder=\\jassrv02\jas-fp$\documents
set ListingFile=filenames.txt
pushd "%ServerFolder%"
dir /B /O:N > "%ListingFile%"
popd

Open in new window

Hope this helps a little, feel free to ask questions.

~bp
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 34241526
==> ok last question what line do I put in this so the command window doesn't pop-up, is there a way to run this in the background?

How are you initiating the script, is it going to be a scheduled thing from the Windows Scheduler, or just clicked on via Windows Explorer when needed to run, etc?

~bp
0
 

Author Comment

by:mtrussell
ID: 34247207
I am going to kick off the command when the end-user needs to look at the file.  It will be an ad-hoc routine.  It is more an administrative 'needle in the haystack' routine I am trying to solve for them.
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 34247733
==> I am going to kick off the command when the end-user needs to look at the file.  It will be an ad-hoc
==> routine.  It is more an administrative 'needle in the haystack' routine I am trying to solve for them.

When you say "kick off" what exactly do you mean, how will you invoke the script?

~bp
0
 

Author Comment

by:mtrussell
ID: 34247855
sorry about that... the code is a procedure behind a button in an Access database.  When the end-user clicks the button it runs the code we have discussed.

One question for you - how do you hide the command prompt entirely from showing up?  the Echooff hides the step by step commands on the screen but is there a way of minimizing the screen?
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 34247937
Can you share the VBA code you are using in the Access database to invoke the BAT script?

It's likely the easiest way to do this is by adjusting the VBA code where you launch the BAT to do it without a window.  Much harder for the BAT file to "hide" its window after it starts.

~bp
0
 

Author Comment

by:mtrussell
ID: 34248087

Here you go.

Call Shell("\\jassrv02\jas-fp$\Documents\filename.bat", 1)

Call DelayTest




DoCmd.OpenQuery "Qry_NotAttachedFiles", acViewNormal, acEdit
0
 
LVL 57

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 34248367
Try this change:

Call Shell("\\jassrv02\jas-fp$\Documents\filename.bat", vbHide)

~bp
0
 

Author Closing Comment

by:mtrussell
ID: 34248468
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question