Take a batch file located at C:\Windows\script.bat You know that this is the location of the batch file, but sometimes you need the batch file to know its own location (C:\Windows\). The %cd% variable returns the current working directory of the script, this is not necessarily the same as the location of it. When you call app.exe from a batch script it will look for this file several places; the Windows PATH variable (%path%) which includes a lot of special directories, such as System32 and the Windows folder, but it will also look in the scripts working directory. This means that if the batch file is located at C:\Windows\, its working directory can be something totally different, such as C:\Users\Calistoga. It's essentially where the script will look when you ask it to work with files without providing a full path. For this reason, %cd% is unreliable if you use the "cd" command in your script, as the the directory you have cd'ed into is the one that will be returned. Now if you look at %~dp0 it's a totally different story. This variable will always return the directory where the script is located, so as such, this is a very reliable option (and the preferred). So you could probably say that this is about getting the location of the script and where it is currently working (it's desktop so to speak). Consider this example, where the script is C:\Windows\script.bat. The script executes the following command: Code: cd "C:\Users\Calistoga" Now the %cd% variable will return C:\Users\Calistoga (since this is where we cd'ed to), while the %~dp0 variable will return C:\Windows (because this is where the script is located). </walloftext>
Great thanks so what's the cmds title just %~dp0 I just need definition to put on first post Tell me how to word it please
Maybe "Get script location and current working directory", eventually just "Obtain script location", You're right, it wasn't that easy to put a word on it Edit: The AutoIt help file defines the macro @ScriptDir (which is the same as %~dp0) as "Directory containing the running script".
So for instance why do we need the location of the script we're running. Example please in .bat file Thanks
Now you're asking a difficult question Let's say you have an app that takes one parameter (a directory path), this app is going to do something with or in that folder. You need it to work with the folder where your script is located, then this variable is useful. As for a specific example... You have two files in a folder. script.bat and app.exe You cd to another directory and try to launch "app.exe" this will fail as the working directory is not where the app.exe is located. Easy fix? Code: %~dp0app.exe This code will always work.
I just started to get it now excellent example. so I've changed first post So tell me if that works for you dude as the way you'd have it be?
Maybe you get scriptor MDL title MDL Scriptor I think so... And any idea's you have for the repo let me know!
I should mention that Powershell is becoming more and more powerful and can even create GUI applications. open Windows Search type Powershell and enter this is in the command line. [reflection.assembly]::LoadWithPartialName( "System.Windows.Forms") $form= New-Object Windows.Forms.Form $button = New-Object Windows.Forms.Button $button.text = "Click Here!" $form.controls.add($button) $form.ShowDialog()
Cna you explain a little more about powershell and what's it's used for mostly? Any comparisons to define it?
I will provide some more information tomorrow as time is short tonight and tomorrow is a holiday so I will have more time then.
Looping Statements: FOR The FOR-loop The art of repeating a piece of code. There are times when you need to process a list of items. Such a list can be for example a list of files in a folder, or a text file containing a list of URL's. Consider the following example: Code: @echo off for %%i in (*.*) do echo %%i pause The part we are interested in is the line starting with for. When executed in a batch file, this code will print a list of all files located in the current working directory. %%i is the iteration variable. Each time the loop evaluates, this variable is updated to the current value. First iteration: %%i = a_file.txt Second iteration: %%i = b_file.txt The (*.*) is the files that will be iterated. Replace the second asterisk with "txt" (*.txt) and the loop will only process txt-files. What you see after do (do echo %%i) is the function that is executed at each iteration for the current value of the iteration variable. You could replace "echo" with "del" and it would delete all files in that directory. To better understand how the loop works, consider this C# example: Code: for (int i = 1; i <= 5; i++) { Console.WriteLine(i); } This code will continue to evaluate until the iteration variable (i) is bigger than 5. The current value of the iteration variable will be printed at each loop. In other words: Evaluate the expression until it is no longer true. At each loop, execute the code inside the brackets and start over again. The following batch example will print all numbers from 1 to 5: Code: @echo off for /l %%i in (1,1,5) do echo %%i pause Notice the /L parameter. This enables the for-loop to iterate through all numbers from 1-5. Why? Consider the following: Code: FOR /L %variable IN (start,step,end) DO command [command-parameters] The first number we used, 1, is the initial value of the iteration variable (start). The second value is the number that should be added to the iteration variable (step) until it finally reaches the last value (end), which is where we want to end up.
Thanks. Tried the code, but the folder created doesn't display the date properly, just shows 0-2010 instead of 31-10-2010. I was wondering if their is a way to fix that. (This was used in Windows 7 64 Bit)
If the %date% variable returns the date as 31-10-2010 then you can use Code: set dest=%date% mkdir %dest% xcopy /is %source% %dest% For me the the %date% returns Sat 10/30/2010, so I had to convert it to 10-30-2010.
The "color" command The "color" command "The screen colors can be configured from the command line itself with the command "color" followed by a two-digit hexadecimal number. The first digit determines the background and the second determines the text color. The table below shows the relationship between the hex numbers and colors. Table I. Hexadecimal color codes 0 = Black8 = Gray 1 = Blue9 = Light Blue 2 = GreenA = Light Green 3 = AquaB = Light Aqua 4 = RedC = Light Red 5 = PurpleD = Light Purple 6 = YellowE = Light Yellow 7 = White F = Bright White For example the command color "0C" will give a black background with red text. Settings made this way apply only to the current session. Entering "color" with no argument will return the system to the starting colors." Example: Code: @echo off @color 0C title Hello World... :MAINMENU mode con: cols=45 lines=4 CLS echo.Hello World... echo. echo. slmgr /dlv pause To open your batch file right click and choose edit...
cool col yea idk how to do this and thanks for sharing the information i wonder what colorful things i can create