Questions about writing a batch file.


  1. Posts : 51
    Windows 7 Home Premium 64bit
       #1

    Questions about writing a batch file.


    Hello everyone,

    I've got some softball questions about writing batch files.

    1)What is the proper syntax to include multiple folders in a set path statement?

    for example I want to run an application called fred.exe and smith.exe.
    Fred is located at c:\scripts\torrent seeds\july\fred.exe
    Smith is located at \\ASUA-HTPC\Datadrive 1\TV Shows 1\smith.exe
    (Note I put spaces within the locations)

    2)When it the % needed around both sides of a variable?

    I have seen %PATH% and %PATH. I have also seen %1 and %1%.

    3)What is the ~ for when associated with a variable?

    Such as SET JOB=%~1

    My batch writing skills are just starting so the simpler explanation the better.

    Thanks for any help you can provide me.
    -Steve
      My Computer


  2. Posts : 370
    Windows 7 Ultimate x64
       #2

    For the first item, are you wanting to run fred.exe in one folder, and smith.exe in another folder? If so, I think you can use the "cd" command in the script before running the programs.
      My Computer


  3. Posts : 51
    Windows 7 Home Premium 64bit
    Thread Starter
       #3

    CreepinJesus said:
    For the first item, are you wanting to run fred.exe in one folder, and smith.exe in another folder? If so, I think you can use the "cd" command in the script before running the programs.
    Thanks for the reply. I think I could use the CD command, but I am not sure that this would work over the network path. I am wanting to run the exe. I'm not sure what you mean by wanting to run the exe in different folders. They are in different folders. They cannot be put into the same folder if that is what you are thinking.
    There should be a way to write these two directories into a path statement so that the exe can be run without changing to the directory where the exe is located. I though that this is what the path statement was used for. Is it used for something else?

    Thanks again for the help
    -Steve
      My Computer


  4. Posts : 8,398
    ultimate 64 sp1
       #4

    it's not the same as answering your specific questions (my knowledge of batch files is pretty weak ),

    but here's a guide which may be useful: batch guide by Terry Newton and here's an a-z list of command syntax by microsoft.

    happy reading
      My Computer


  5. Posts : 51
    Windows 7 Home Premium 64bit
    Thread Starter
       #5

    mickey megabyte said:
    it's not the same as answering your specific questions (my knowledge of batch files is pretty weak ),
    No problem.

    mickey megabyte said:
    but here's a guide which may be useful: batch guide by Terry Newton and here's an a-z list of command syntax by microsoft.

    happy reading
    That is a helpful guide. I found the MS syntax list, however it reads like stereo instructions if you get my drift.

    I'll leave this not solved just yet in case there are others that have the answer, but thanks for the guide link. Will be happy to read other guides too.

    -Steve
      My Computer


  6. Posts : 934
    Windows 8.1 ; Windows 7 x86 (Dec2008-Jan2013)
       #6

    1) To make cmd understand spaces you need to put the whole path in brakets.

    "c:\scripts\torrent seeds\july\fred.exe"
    As far as I know you can not put multiple folder locataions in one variable. But you can set a second one like:
    Code:
    set path="c:\scripts\torrent seeds\july\fred.exe" 
    set smith="\\ASUA-HTPC\Datadrive 1\TV Shows 1\smith.exe" 
    ... 
    %path% 
    %smith%
    %path% will execute fred.exe and %smith% will execute smith.exe

    2) %X% will be calling variable, which was set beforehand as X

    %1 will be calling value of first parameter passed to a script, %2 - second etc.

    3)
    http://goo.gl/52ttz said:
    The leading tilde is used to decompose elements in a batch file parameter formatted as a path, such as the parent directory or file extension.
    http://goo.gl/kO9Hj said:
    Parameter Description
    %1 The normal parameter.
    %~f1 expands %1 to a fully qualified path name.
    %~d1 expands %1 to a drive letter only.
    %~p1 expands %1 to a path only.
    %~n1 expands %1 to a file name only (prefix)
    %~x1 expands %1 to a file extension only.
    %~s1 changes the meaning of n and x options to reference the short name.

    %~dp1 expands %1 to a drive letter and path only.
    %~nx1 expands %1 to a file name and extension only.
    Additional parameter extensions available in Win2K / XP:
    %~1 - expand %1 removing any surrounding quotes (")
    %~a1 - display the file attributes of %1
    %~t1 - display the date/time of %1
    %~z1 - display the file size of %1
    %~$PATH:1 - search the PATH environment variable and expand %1 to the fully qualified name of the first match found.
      My Computer


  7. Posts : 51
    Windows 7 Home Premium 64bit
    Thread Starter
       #7

    That was a great explanation. Thanks Neutron16.
    -Steve
      My Computer


  8. Posts : 370
    Windows 7 Ultimate x64
       #8

    nzdreamer55 said:
    CreepinJesus said:
    For the first item, are you wanting to run fred.exe in one folder, and smith.exe in another folder? If so, I think you can use the "cd" command in the script before running the programs.
    ... I'm not sure what you mean by wanting to run the exe in different folders. They are in different folders...
    What I meant was you can run applications with a certain location as their "root" location.

    For example, you could have a batch script that is simply "dir /B". If you run this script in, let's say, Folder A, it will list the contents of Folder A. But, "cd" to Folder B and run it from there, and it will list the contents of Folder B. It's the same script, but run from different locations.
      My Computer


  9. Posts : 3,371
    W10 Pro desktop, W11 laptop, W11 Pro tablet (all 64-bit)
       #9

    You really don't want to use Path as a variable in this instance since Path is a system variable and if you set it in a batch file it may have undesirable effects.

    When you type in a command at a command prompt, the current folder is searched for that command and if it isn't found then folders listed in the Path system variable are searched. Multiple folders can be put on a Path variable, separated by a semicolon. In a batch file that changes the path you generally concatenate to it instead of replacing it such as:

    SET PATH=PATH;C:\NewFolder;D:\AnotherFolder

    If you want to see what the path is currently set to just enter path at a command prompt.
      My Computer


  10. Posts : 51
    Windows 7 Home Premium 64bit
    Thread Starter
       #10

    Thanks everyone for the answers. Got my bat file working
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:26.
Find Us