Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: About percentage sign '%'  (Read 4976 times)

0 Members and 1 Guest are viewing this topic.

nero

  • Guest
About percentage sign '%'
« on: January 11, 2008, 05:14:40 AM »
hallo...
how do i use this % sign in my batch file?
any guidance...?


Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: About percentage sign '%'
« Reply #1 on: January 11, 2008, 06:22:48 AM »
Quote
how do i use this % sign in my batch file

In batch code the % sign is used to reference command line arguments and variables generated by the for command. It can also be used in a set statement as an arithmetic operator. Sometimes however, a percent sign is just a percent sign. How do you want to use it?
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

nero

  • Guest
Re: About percentage sign '%'
« Reply #2 on: January 11, 2008, 08:19:00 AM »


Quote
to reference command line arguments and variables generated by the for command

i couldn't get the meaning? could u xplain through thi code....

Search directory for folder and file names.
for /f "tokens=* delims=" %%x in ('dir %INPUT_FOLDER% /b/ad') do move %INPUT_FOLDER%"%%x" %OUTPUT_FOLDER%
 

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: About percentage sign '%'
« Reply #3 on: January 11, 2008, 02:08:59 PM »
Your code looks fine (I adjusted the quotes and added a backslash)  ;)

Code: [Select]
for /f "tokens=* delims=" %%x in ('dir %INPUT_FOLDER% /b/ad') do move "%INPUT_FOLDER%\%%x" %OUTPUT_FOLDER%

Not sure what the question is though. Environment variables are set by system (type set at a command prompt to see the system variables) or by the user. You can set your own by using the set statement in your file for INPUT-FOLDER and OUTPUT_FOLDER.

Code: [Select]
set input_folder=somevalue
set output_folder=someothervalue
for /f "tokens=* delims=" %%x in ('dir %INPUT_FOLDER% /b/ad') do move "%INPUT_FOLDER%\%%x" %OUTPUT_FOLDER%

You can also pass the values of input_folder and output_folder on the command line, but then the reference changes. For instance if your batch file is named mybatch, you can pass the values of input_folder and output_folder on the command line:

mybatch somevalue someothervalue

You code changes because the reference is different:

Code: [Select]
for /f "tokens=* delims=" %%x in ('dir %1 /b/ad') do move "%1\%%x" %2

You can have up to 9 defined command line parameters (%1-%9). %0 is the name of the batch file (mybatch in this case). You can have more than 9 but you have to shift which makes for some lively coding.

Passing variables on the command line makes your batch code more useful...you can determine at run time what values to pass to the batch file as opposed to hardcoding them. 8)

PS. The move command is for files not folders.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

nero

  • Guest
Re: About percentage sign '%'
« Reply #4 on: January 11, 2008, 02:40:35 PM »
Quote
You can have up to 9 defined command line parameters (%1-%9). %0 is the name of the batch file (mybatch in this case).

could you show step by step through simple example....

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: About percentage sign '%'
« Reply #5 on: January 11, 2008, 04:34:52 PM »
Quote
could you show step by step through simple example....

I thought I had. Oh well, there goes the writing career ;D. Perhaps you can get a fresh perspective from:

Link 1

OR

Link 2

OR

Link 3

Good luck.  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein