Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Location of Chrome Extension Source code on Windows

C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\Extensions

Using FOR loop in batch files

FOR

Conditionally perform a command on several files.
Syntax
      FOR %%parameter IN (set) DO command

Key
   set         : A set of files, separated by any standard delimiter.

   command     : The command to carry out, including any 
                 command-line parameters.

   %%parameter : A replaceable parameter:
                 e.g. in a batch file use %%G 
                      (on the command line %G)
Examples

Copy a single file
FOR %%G IN (MyFile.txt) DO copy %%G d:\backups\

Copy a list of several files
FOR %%G IN (Myfile.txt SecondFile.txt) DO copy %%G d:\backups\
FOR %%G IN ("C:\demo files\file1.txt" "C:\demo files\File2.txt") DO copy %%G d:\backups\

Copy a single file
FOR %%G IN (c:\program^ files\MyFile.txt) DO copy %%G d:\backups\

In the line above the source folder has spaces that need to be escaped with ^

Although wildcards can be used an alternative method of processing files is to process the output of the command 'DIR /b'

This can be useful when you want to use some of the other DIR options like sorting.
FOR is an internal command.
"Darkness reigns at the foot of the lighthouse" ~ Japanese Proverb

Related:

FOR - Loop commands
FOR /R - Loop through files (recurse subfolders)
FOR /D
- Loop through several folders
FOR /L - Loop through a range of numbers
FOR /F - Loop through items in a text file
FOR /F - Loop through the output of a command
FORFILES - Batch process multiple files
GOTO - Direct a batch program to jump to a labelled line
IF - Conditionally perform a command
Equivalent bash command (Linux): for - Expand words, and execute commands


Ref: http://ss64.com/nt/for2.html

Batch Files - How to set command output as a variable

 
FOR /F "tokens=* USEBACKQ" %%F IN (`command`) DO (
SET var=%%F
)
ECHO %var%

I always use the USEBACKQ so that if you have a string to insert or a long file name, you can use your double quotes without screwing up the command.
Now if your output will contain multiple lines, you can do this
 
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`command`) DO (
  SET var!count!=%%F
  SET /a count=!count!+1
)
ECHO %var1%
ECHO %var2%
ECHO %var3%
ENDLOCAL

How to extract files from MSI package or installer

First, access an elevated command prompt, to do this:
  1. Click the Start button.
  2. Click All Programs.
  3. Go into Accessories.
  4. Right-click on Command Prompt.
  5. Select Run as administrator.
  6. When the UAC Prompt appears, click Continue.
Once you have your elevated command prompt, input the following:
<pre>

msiexec /a filepath to MSI file /qb TARGETDIR=filepath to target folder

</pre >
using the desired locations to fill the above mentioned filepaths.

 (Example: msiexec /a c:\testfile.msi /qb TARGETDIR=c:\temp\test)