I am writing a batch file which will identify the names of all .jak files in a directory (location specified) and convert them to .java files using AHEAD composer.
The batch file code:
#echo off
set PATH=%PATH%;C:\AHEAD\ahead-v2013.03.20\build\bin;
set PATH=%PATH%;C:\Program Files\Java\jdk1.7.0\bin;
set PATH=%PATH%;C:\Program Files\apache-ant-1.9.3\bin;
set PATH=%PATH%;C:\AHEAD\ahead-v2013.03.20\miscellaneous\javacc\bin;
set PATH=%PATH%;C:\Cygwin\bin;
dir C:\AHEAD\JAK\*.jak /b >> list.txt
for /F "tokens=*" %%a in (list.txt) do call :Foo %%a
goto End
:Foo
set z=%1
echo %z%
jak2java %z%
goto :eof
:End
PAUSE;
cmd
With this i am getting the error System cannot find batch label specified -Foo
But the same program works well for javac command and .java files
Not possible; I tried a simplified version of your code (as below) and it worked fine.
Most probably it's a file format issue. Make sure that the file is in DOS format. Best is; copy the above posted code to a new editor (say, notepad) and save it with *.bat extension and then try running it.
Check out this threads as well
Why "The system cannot find the batch label specified" is thrown even if label exists?
http://help.wugnet.com/windows/system-find-batch-label-ftopict615555.html
#echo off
dir D:\Songs-mp3\English\*.mp3 /b >> list.txt
for /F "tokens=*" %%a in (list.txt) do call :Foo %%a
goto End
:Foo
set z=%1
echo %z%
goto :eof
:End
PAUSE;
cmd
Related
can someone please help how to find specific folders with size 0 under directory using batch? thank you.
there are many folders in a parent folder, some of them have files inside and some folder are empty. I'd like to find out the name of the empty folders using batch file. can someone help? thanks
This script scans the target folder and returns the UNC paths of all empty subfolders within the target folder.
#echo off
setlocal EnableDelayedExpansion
REM This script scans the target folder and returns the UNC paths of all empty subfolders within the target folder.
title Looking for empties, please wait!
cd "%~dp0"
cls
if "%~1" == "" (
echo ERROR: No folder was specified! You gotta tell me where to look for empties!
echo Please drag-and-drop a folder onto the icon for this script.
pause
exit /b
)
if not exist "%~dpn1" (
echo ERROR: The folder you told me to scan doesn't seem to exist!
pause
exit /b
)
set "target=%~dpn1"
echo Scanning: %target%
echo.
REM Grab each subfolder for checking.
for /f "tokens=*" %%a in ('dir "%~dpn1" /s /b /a:d') do (call :checkForBlanks "%%a")
echo.
echo Done.
title Done.
pause
exit /b
:checkForBlanks
REM We've been given a folder. We must check if it's empty.
set "folder=%~1"
set "scanned=!folder:%target%=!"
title Looking for empties: %scanned:&=^&%
set exist=
for /f %%a in ('dir "%~1" /b') do (set "exist=%%a" & goto :found)
:found
if "%exist%" == "" echo EMPTY: %scanned:&=^&%
goto :eof
The following batch-file idea, which leverages powershell may provide the information you require.
I say, may, because you've not clarified what you deem to be an empty subfolder, or folder with size 0.
The following single line batch file example should work regardless of the installed powershell.exe version:
#(For /F "Delims=" %%G In ('%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoP "(GCI -Rec|?{$_.PSIsContainer -Eq $True})|?{$_.GetFileSystemInfos().Count -Eq 0}|Select -Exp FullName" 2^>NUL')Do #Echo/%%G)&Pause
If you're using a more up to date version of powershell.exe, perhaps the following example may be preferable for you:
#(For /F "Delims=" %%G In ('%__AppDir__%WindowsPowerShell\v1.0\powershell.exe -NoP "GCI -AD -S|?{$_.GetFileSystemInfos().Count -Eq 0}|Select -Exp FullName" 2^>NUL')Do #Echo/%%G)&Pause
Both examples are designed to recurse from the current directory, if you wish to insert the base directory directly into the for loop then use it just after GCI in whichever example you choose, (preferable enclosed between single straight quotes)
Just so you know, im no wizard at writing batch scripts and I don't yet understand many things about them.
I need to select a file using the path of the batch scripts folder that has a certain file extension.
Here is what I have so far.
echo select vdisk file="%~dp0Test.vhd"
I want to be able to select this file with the path of the batch script but also not require a file name for me to select it but instead just use the file extension type so that I can change the file (with the same extension type) but the batch script will still select it.
I hope that made sense...
for %%a in ("%~dp0*.vhd") do echo select vdisk file="%~dp0%%a"
Note: if there is more than one matching file, this will execute the command (echo ...) for each of them.
The following example gives you the best of both worlds. If you have only one .vhd file alongside the batch file it will be auto selected as required. If there is more than one .vhd file, you will be presented with a selection menu to choose the one you need.
#Echo Off
If Exist "%~dp0*.vhd" (CD /D "%~dp0" 2>Nul) Else Exit /B
SetLocal EnableDelayedExpansion
For /F "Delims==" %%A In ('"(Set vhd[) 2>Nul"') Do Set "%%A="
Set "i=0"
For %%A In ("*.vhd") Do (Set /A i+=1 & Set "vhd[!i!]=%%~nA")
If %i% Equ 1 (Set "vhd[X]=%vhd[1]%") Else Call :Menu
Rem Example DiskPart commands using selected .vhd begin below
( Echo select vdisk file="%~dp0%vhd[X]%.vhd"
Echo attach vdisk)>"DPscript.txt"
DiskPart /s "DPScript.txt"
Rem Example DiskPart commands using selected .vhd end above
Exit /B
:Menu
For /L %%A In (1,1,%i%) Do (Echo %%A. !vhd[%%A]!)
Set /P "vhd[X]=Select a .vhd from the above list: "
If Not Defined vhd[%vhd[X]%] (ClS & GoTo Menu)
Set "vhd[X]=!vhd[%vhd[X]%]!"
I am creating a batch file to open remote Computer Management console by taking User ID as input and computer name from 2nd column from file data.csv. it works fine on first attempt. When it goes back to :start label. and ask for other input. it gives error. System cannot find file ./data.csv
My code is
:start
set /p Input="Enter User-ID:"
for /f "usebackq tokens=1-4 delims=," %%a in (".\data.csv") do (
if %input% ==%%a ("cmd /c Start /B /wait compmgmt.msc –a /computer=%%b")
)
cls
GOTO start
Good practice to use %~dp0 for paths in batch files (instead of relative paths like .) that way if the current working folder changes the file will always be located.
So change to %~dp0data.csv
:start
set /p Input="Enter User-ID:"
PUSHD
for /f "usebackq tokens=1-4 delims=," %%a in (".\data.csv") do (
if %input% ==%%a ("cmd /c Start /B /wait compmgmt.msc –a /computer=%%b")
)
POPD
cls
GOTO start
should restore sanity, pushing the directory then restoring it before the next cycle.
I want to write a script to prompt user for file path and list all files found. The file path can contain wildcards. Something similar to this. But the batch script version of it. For example:
C:\Somewhere\user*\app\version-*.*\start.exe
The files might be located like this:
C:\Somewhere\user345\app\version-1.0\start.exe
C:\Somewhere\user898\app\version-1.2\start.exe
C:\Somewhere\user898\app\version-1.3\start.exe
I tried to use FOR and it turns out to be so much harder than expected because FOR does not support wildcards in the middle of a path.
Is there a way to list these files? (Maybe without using for?)
I think this recursive solution works pretty well; you may name it WCDIR.bat:
#echo off
setlocal
if "%~1" neq "" set "next=%~1" & goto next
echo Show files selected by several wild-cards
echo/
echo WCDIR wildcardPath
echo/
echo Each folder in the path may contain wild-cards
echo the last part must be a file wild-card
goto :EOF
:next
for /F "tokens=1* delims=\" %%a in ("%next%") do set "this=%%a" & set "next=%%b"
if defined next (
for /D %%a in ("%this::=:\%") do (
setlocal
cd /D "%%~a" 2>NUL
if not errorlevel 1 call :next
endlocal
)
) else (
for /F "delims=" %%a in ('dir /B /A:-D "%this%" 2^>NUL') do echo %%~Fa
)
exit /B
EDIT: I fixed a small bug in the last for /F command.
For example, the output of WCDIR.bat C:\Windows\Sys*\find*.exe command in my Windows 8.1 64-bits computer is:
C:\Windows\System32\find.exe
C:\Windows\System32\findstr.exe
C:\Windows\SysWOW64\find.exe
C:\Windows\SysWOW64\findstr.exe
You can try with the command Where /?
The WHERE command is roughly equivalent to the UNIX 'which' command. By default, the search is done in the current directory and in the PATH.
#echo off
Where /R "%programfiles%" *winrar.exe
pause
#echo off
:: Example d'input
set UserInput=*drive*
:: building the Pattern
set cmd=%Userinput%.exe
:: storage Where.exe command in a macro, the execution will be faster
set whereCmd=where.exe /r c:\windows\ %cmd%
:: execution of macro and output formatting
for /f %%a in ('%whereCmd%') do echo %%~nxa --^> %%a
pause
Ok, I am trying to make a batch file to generate a series of files and folders, but can't find on how to do it.
My Idea:
FOR /f "Tokens=* delims=" %%I IN (export2.csv) DO call:create %%I GOTO:EOF
:create ECHO 1 >>%~pd0%1
But it didn't work at all.
Since I have no idea how your data file looks like it's hard to give good advice here, but your code could be cleaned up a bit:
set "filepath=%~dp0"
for /f "tokens=* delims=" %%I in (export2.csv) do call :create "%%I"
rem This is needed to avoid stepping into the subroutine again
goto :eof
:create
rem This will create an empty file instead of one that contains a single line with 1
copy nul "%filepath%%~1"
goto :eof
This won't create any directories, though. You can create those with md.
Figured it out a little bit ago and here is what I ended up with. It will generate both the path and create an empty file with the name of the file listed in the masterlist.csv.
Source Code
#ECHO OFF
CHDIR "%~dp0"
SET Count=0
ECHO/ Generating Necessary File, please Wait...
FOR /F %%A IN (Masterlist.csv) DO CALL:MKDIR %%A
EXIT /B
:MKDIR
SET /A Count+=1
SET "Path=%~dp1"
SET "File=%~nx1"
IF NOT EXIST "%Path%" MKDIR "%Path%
IF NOT EXIST "%Path%" CALL:ERROR "Path"
IF NOT EXIST "%Path%\%File%" ECHO/ >>"%Path%\%File%"
IF NOT EXIST "%Path%\%File%" CALL:ERROR
EXIT /B
:ERROR
IF NOT EXIST "Errorlog.csv" ECHO Error, Line Count>>Errorlog.csv
ECHO %~1, Line %Count%>>Errorlog.csv
A few example lines from Masterlist.csv
2006\MS06-003\Office2000\office2000-kb892842-fullfile-enu.exe
2006\MS06-003\Office2003\office2003-kb892843-fullfile-enu.exe
2006\MS06-003\Office2003\WinSec-MS06-003-009-P44333-outlook2003-kb892843-fullfile-enu.exe
2006\MS06-003\OfficeXP\officexp-kb892841-fullfile-enu.exe
2006\MS06-006\WindowsMedia-KB911564-x86-ENU.exe
2006\MS06-007\2003\WindowsServer2003-KB913446-x86-ENU.exe
2006\MS06-007\XP\WindowsXP-KB913446-x86-ENU.exe
2006\MS06-012\2003\office2003-KB905756-FullFile-ENU.exe
2006\MS06-015\2000\Windows2000-KB908531-x86-ENU.EXE
2006\MS06-015\2003\WindowsServer2003-KB908531-x86-ENU.exe