Useful commands used in Windows commands shell


As Unix script language is actually quit powerful to do manipulate text, files/directories and so on, on Windows machine, there are many ways to do the same jobs. Here some useful examples which can be used in normal Windows .bat or .cmd and are also quit helpful in many option menus supported in Visual Studio. For example, before actual compilation of a project, someone may want to copy or create resources necessary to build binary to certain location or add a time stamp string to many source code files. For this purpose, we can add custom commands in Pre-build Event options of Visual Studio property setting window. 


So hope these examples show you a guidance on that. Again this information were taken from various link which I cannot remember correctly.



1. Searching files having specific extension in its file name in current folder


for %%f in (*.java *.cmd) do echo  %%f


2. Searching files with .java extension recursively  


dir /b /s /a-d | findstr /i ".java$


3. Find and delete files with certain name recursivly

 i) In batch file,

    for /f "usebackq" %%i in (`dir /s /b ^| find "Makefile"`) do echo %%i

 ii) In command line,

    for /f "usebackq" %i in (`dir /s /b ^| find "Makefile"`) do echo %i


 ** Note: replace "echo" with "del" to delete file instead of echoing file name.


4. Create array containing file names with full path located in specific folder. Note: In Windows there seems a limitation in assigning array from command line with use of pipe. So this is different trial to do that.

setlocal enabledelayedexpansion enableextensions

set LIST=

for %%x in (javaSourceFolder\*.java) do set LIST= %%x

set LIST=%LIST:~1%


5. Compiling all java files located at specific folder

---- Assuming %LIST% having file list with full path  ---

for %%f in (%LIST%) do (

 "$(JDK_ROOT)\bin\javac.exe" -d $(IntDir)$(JavaOutputDir) -classpath $(IntDir)$(JavaOutputDir) -classpath $(AndroidSdkApiDir)/android.jar %%f

)


6. QT

When you need to decide which build configuration among 32bit and 64bit, don't forget to keep using only one configuration. For example, if you develop qt application using Visual Studio C/C++ 20xx and want to use command prompt to build it, you need to choose build environment among 32bit, 64bit and 64bit_opengl. Once you pick one among them, DON'T FORGET to call proper bat file for Visual Studio compilation setup.


If you want 32bit QT application, run below command after opening QT command prompt

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\vcvarsall.bat" x86


If you want 64bit QT application, run below command after opening QT command prompt

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\vcvarsall.bat" x64


7. later...


Posted by kevino
,
http://www.blogsdna.com/2166/how-to-delete-undeletable-files-in-windows-7.htm

비스타와 windows 7으로 오면서 바뀐 보안관리 정책으로 과거 XP에서 생성되었던 파일들이 vista나 windows 7으로 오면서 삭제가 되지 않던 문제가 있는데 다음과 같은 명령어를 사용하면 쉽게 파일이나 디렉토리를 삭제할 수 있다.

잊지 말아야 할 것은 다음의 명령어를 일반 커맨드창에서 사용하면 허가권이 없다고 하면서 실패하므로 관리자 권한으로 창을 띄운 후 명령어를 입력해야 한다. 예제에서는 계정을 administrator로 하였지만 자신의 계정으로 이름을 바꿀수도 있다.

For Files:

takeown /f file_name /d y
icacls file_name /grant administrators:F

For Directories (will perform action recursively):

takeown /f directory_name /r /d y
icacls directory_name /grant administrators:F /t

Please keep in mind above syntaxes will grant full permission to administrator group hence you must be a part of administrator group to take advantage of above command.

Posted by kevino
,