I have an executable which when run asks for the name of the parameter file. I have tried all styles of inputting the parameter file's name but I get the same error which is:
GAM Version: 2.905
ERROR - the parameter file does not exist,
check for the file and try again
Stop - Program terminated.
ans =
0
The name of the parameter file is gam.par. The various styles that I have tried for the function to automatically read the parameter file's name are:
system('"gam.exe" -f "gam.par"')
system('"gam.exe" -f "gam.par"')
system('"gam.exe" -f gam.par')
system('gam.exe -f gam.par')
system('"gam.exe" /f gam.par')
system('"gam.exe" /f gam.par /o gam.out')
system('"C:\Users\...\gam.exe" /f gam.par /o gam.out')
system(['"C:\Users\...\gam.exe" /f gam.par /o gam.out'])
Where gam.par and gam.par are parameter (input) file and output file, respectively. However, in each of the above case I get the same error message as shown in the beginning.
All my files (input, output, executable etc.) are in same folder. If I use the system() function without using the parameter file's name then it runs without fault and prompts me to enter the parameter file name and when I enter the same file name (i.e. gam.par) on prompt then everything works fine. I want to be able to do that automatically by entering the parameter file name inside the system() argument rather than entering manually on prompt. It will be helpful if anyone can determine why I am not able to get what I am trying to do. Thanks!
According to this page from Mathworks, the syntax is:
system('filename parameter1 parameter2...parameterN')
or in your case:
system('gam.exe gam.par')
Notice the single quotes around the entire argument as well as the spaces between each parameter being passed to the executable application. There is also the full product documentation but I find it less clear than my previous link.
Here is an example. Imagine you had a text file at: C:\filename.txt:
system('type c:\filename.txt')
Now if the file had spaces in its name (or its path), you need to use double quotes:
system('type "c:\my filename.txt"')
Run program in console: \\location\My programm.exe 'param 1' 'param 2'
Run program in Matlab: system(['location\my proramm.exe' '"param 1"' '"param 2')
pathApplicationForm = strcat('"C:\Users\Master\Google Drive\Bakalaura Darbs\Application Development for the Microscopic Models Calibration\Application Form\bin\Debug\Application Form.exe"');
runParam = strcat(get(vEdit2,'String'), '\', get(vEdit3,'String'));
VISSIM = strcat(get(vEdit1,'String'));
system([pathApplicationForm ' "' VISSIM '" "' runParam '']);
It's working ^^
Related
I have 30 different folders which I need to iterate thru, within each one there’s a Log folder and inside that, are the text files. I’m after the latest one, which I need to copy to the new location with the preferred name (E.G. 2020-03-28.txt.FolderServerName1, where appended variable FolderServerName1, identifies from which server it came from)
set source="\\ServerName\LogFolders"
set target=" C:\Data\CopiedLogFiles"
FolderServerName1
Log
2020-03-26.txt
2020-03-27.txt
**2020-03-28.txt**
FolderServerName2
Log
2020-03-26.txt
2020-03-27.txt
**2020-03-28.txt**
FolderServerName3
Log
2020-03-26.txt
2020-03-27.txt
**2020-03-28.txt**
https://devblogs.microsoft.com/oldnewthing/20120801-00/?p=6993
The post above is very useful, but I think I need another nested loop within, which I'm struggling with syntactically.
Thank You so much!
This file copying task can be done with:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
for /D %%I in ("\\ServerName\LogFolders\*") do (
set "CopyDone="
for /F "delims=" %%J in ('dir "%%I\Log\20??-??-??.txt" /A-D-H /B /O-N 2^>nul') do if not defined CopyDone (
copy /Y "%%I\Log\%%J" "C:\Data\CopiedLogFiles\%%~nJ_%%~nxI%%~xJ" >nul
set "CopyDone=1"
)
)
endlocal
For each non-hidden subdirectory in \\ServerName\LogFolders the outer FOR loop first deletes the environment variable CopyDone and runs one more FOR loop.
The inner FOR loop starts in background one more command process using %ComSpec% /c and the command line enclosed in ' as additional commands. So executed with Windows installed into C:\Windows is in background for example:
C:\Windows\System32\cmd.exe /c dir "\\ServerName\LogFolders\FolderServerName1\Log\20??-??-??.txt" /A-D /B /O-N 2>nul
The command DIR searches in specified directory
only for non-hidden files because of option /A-D-H (attribute not directory and not hidden)
with a file name matching the wildcard pattern 20??-??-??.txt
and outputs in bare format because of option /B just each file name with extension without path
ordered reverse by name because of option /O-N
to handle STDOUT (standard output) of the background command process.
The reverse output sorted alphabetically by name results for the log file names that 2020-03-28.txt is output on first line, 2020-03-27.txt on second line and 2020-03-26.txt on third line.
It could be that the subdirectory Log does not exist at all or does not contain any file matching the wildcard pattern. In this case command DIR outputs an error message to handle STDERR (standard error) which is suppressed by redirecting it to device NUL with 2>nul.
Read the Microsoft article about Using command redirection operators for an explanation of 2>nul. The redirection operator > must be escaped with caret character ^ on FOR command line to be interpreted as literal character when Windows command interpreter processes this command line before executing command FOR which executes the embedded dir command line with using a separate command process started in background.
The command process processing the batch file captures everything written to handle STDOUT of background command process and FOR processes this captured output line by line after started cmd.exe terminated itself.
FOR ignores empty lines which do not occur here.
FOR would split up by default each line into substrings using normal space and horizontal tab character as string delimiters, would next look if first substring starts with default end of line character ; in which case the line would be also ignored and otherwise would assign just first space/tab delimited string to specified loop variable. It would be possible here to use this default line processing behavior as the file names do not contain a space character. But it is nevertheless better to disable line splitting behavior by using delims= to define an empty list of string delimiters.
So the inner FOR assigns on first loop iteration the file name of newest file according to international formatted date in file name to loop variable J and runs the command IF.
On first loop iteration of the inner FOR loop the environment variable CopyDone is always not defined as made sure on the command line above and so the IF condition is true.
For that reason the file is copied which means for first folder FolderServerName1 that the executed COPY command is:
copy /Y "\\ServerName\LogFolders\FolderServerName1\Log\2020-03-28.txt" "C:\Data\CopiedLogFiles\2020-03-28_FolderServerName1.txt" >nul
The target file name is modified from requested 2020-03-28.txt.FolderServerName1 to 2020-03-28_FolderServerName1.txt. It is in general better to use a dot in the name of a file just once as separator between file name and file extension and keep the file extension at end of the name of the file to be able to open the file with a double click.
The environment variable CopyDone is defined with a value after the file copying is done without verification on success. The string value assigned to environment variable CopyDone does not matter in this case.
The inner FOR continues processing the captured lines by assigning one file name after the other to loop variable J and running the IF condition. But this condition is not true for any other file name than the first file name.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
copy /?
dir /?
echo /?
endlocal /?
for /?
if /?
set /?
setlocal /?
I am trying to run beyond compare via command line.
The command I am using is :
BCompare.exe #"My Config File.txt" "File 1.xml" "File 2.xml"
But this is not working because of spaces in the file Names.
Beyond Compare shows a "file not found" error (as it is looking only for the part of fileName before spaces)
If I compare files without any space in file name, it works.
Since you're running a script but haven't shown that, I suspect you aren't quoting the arguments there properly. The quotes on the command line are going to be stripped as part of the command line processing, so if your script is:
file-report layout:side-by-side %1 %2 output-to:printer
It should actually be
file-report layout:side-by-side "%1" "%2" output-to:printer
Without the extra quotes the variables would be expanded like:
file-report layout:side-by-side File 1.xml File 2.xml output-to:printer
I need to write a .bat or .cmd script that will find all instances of file type .log in the directory it is run from, and for each of those search it for "searchstring", counting how many times it appears. Then I need to rename the file (original name: "[name].log") to "name.log". This is to enable me to get a very quick visual count of the number of errors in a file (which is part of what the log contains).
I've already got the for loop that locates all *.log files, but how do I count instances of a particular string?
try this:
for /f "tokens=2delims=:" %a in ('find /c "string" *.log') do #set /a count+=%a
echo %count%
Code is for shell prompt. For shell file replace %a with %%a.
How would I write a batch file to rename multiple text files?
Suppose we have to rename 200 files as below
ABC_Suman_156smnhk.txt,
ABC_Suman_73564jsdlfm.txt,
ABC_Suman_9864yds7mjf45mj.txt
To
MNC_Ranj_156smnhk.txt,
MNC_Ranj_73564jsdlfm.txt,
MNC_Ranj_9864yds7mjf45mj.txt
Note: I need this ABC_Suman part only changed to MNC_Ranj
Any help would be appreciated.
To perform a batch rename, the basic command looks like this:
for filename in foo; do echo mv \"$filename\" \"${filename//foo/bar}\"; done > rename.txt
The command works as follows:
The for loop goes through all files with name foo in the current directory.
For each filename, it constructs and echoes a command of the form mv “filename” “newfilename”, where the filename and new file name are surrounded by double quotes (to account for spaces in the file name) and the new file name has all instances of foo replaced with bar. The substitution function ${filename//foo/bar} has two slashes (//) to replace every occurrence of foo with bar.
Finally, the entire output is saved to rename.txt for user review to ensure that the rename commands are being generated correctly.
i took it from the following link:
http://www.peteryu.ca/tutorials/shellscripting/batch_rename
#echo off
setlocal enableDelayedExpansion
for %%F in (ABC_Suman*.txt) do (
set "name=%%F"
ren "!name!" "!name:ABC_Suman=MNC_Ranj!"
)
How can I open any type of file in a .bat by providing only a name of the file, no extension?
I want to let windows decide the application to use.
example:
%SystemRoot%\explorer.exe E:\SomeFolder\
%SystemRoot%\explorer.exe E:\SomeFolder\file1
Use START command:
start "Any title" E:\SomeFolder\
start "Any title" E:\SomeFolder\file1
Taken from Start help:
If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:
.
non-executable files may be invoked through their file association just
by typing the name of the file as a command. (e.g. WORD.DOC would
launch the application associated with the .DOC file extension).
See the ASSOC and FTYPE commands for how to create these
associations from within a command script.
.
When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name. If it does, the
START command launches the Explorer on that path. If done from the
command line, it is the equivalent to doing a CD /D to that path.
Note that previous description imply that the pure filename must also execute the right application, with no START command. To pick up the first file with a given name:
for %%f in (name.*) do set "filename=%%f" & goto continue
:continue
... and to execute it:
%filename%
PS - Note that you want "to let windows decide the application to use", but in your example you explicitly select %SystemRoot%\explorer.exe as the application to use. So?