Renaming file using WinSCP - windows

I've created a file names upload.winscp with this content:
option batch abort
option confirm off
rename cinta.dmp cinta_bck.dmp
exit
which I call from a bat file with this content
winscp.com /script="E:\upload.winscp" /log="E:\upload.winscp.log"
but when I run the bat file, the file is not renamed, neither the log created

Your script does not open any connection (what is also the reason that no log file is created).
You are missing open command:
open ftp://username:password#example.com/
rename cinta.dmp cinta_bck.dmp
exit
Or you misunderstood the purpose of WinSCP.

Related

Can't open a .chm file from a batch file

I am trying to open a .chm file from a batch file.
The batch file has only this text in it :
echo off
start "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
If I run the batch file, the commandline opens but nothing further happens.
If I copy paste S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm in start menu/run then it does works.
If I make a shortcut with target "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm" then it also works.
So the command works everywhere, except from a batch file.
What am I doing wrong here ?
It might also be important to know that when I start it from the shortcut, or start menu/runI always get a dialog
We can't verify who created this file. Are you sure you want to open this file ?
I am using Windows 7
EDIT
My problem is not the dialog, my problem is that nothing happens when I open the chm file from a batch file
The Start command is probably seeing your doublequoted string as a title, enter Start /? at the command prompt for its usage information.
Try adding an empty title first:
#Echo Off
Start "" "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"

How to set a go to a directory and execute a command in a batch file?

During the deployment of the windows application that I make, I have to run a few commands in the CommandPrompt to update the database. I was thinking of making a batch file to automate this process so that the user can update the database just by double-clicking the batch file. Following is the screenshot for the same.
I want my batch file to go to the current directory where the .bat file is located.
Then i want to execute the DBUpdater exe file against the config file.
I am new to batch programming so anything informative will help a lot. Thank you.
Create a batch file named DBUpdater.bat in any directory of your choice with the below script:
#ECHO OFF
setlocal
cd /d %~dp0
DBUpdater.v15.2.exe OfficeManagement.win.exe.config
This assumes that the OfficeManagement.win.exe.config file exists in the same directory as batch file and that DBUpdater.v15.2.exe is recognized as a global command.

Calling a batch file from another batch file in different directory - resources not found

I'm working with installshield and have a group of batch files that I want to run as part of the install process. Instead of executing each batch file from installshield I want to create one batch file that executes all of the batch files.
The issue I have is that the calling batch file sits two directories up from the others. When the batch file tries to call the others they fail to run because they can not find the resources that they need. It seems that when they are executed from the batch file two directories up they are for some reason using the relative path of the calling batch file. Is my assumption correct?
One of the batch files that I am calling is a batch file to star an h2 database the call looks like this:
call h2\bin\h2.bat
If I go to the /h2/bin directory in a command prompt the h2.bat runs fine but once I run it from the calling batch file this is the error that I get.
Error: Could not find or load main class org.h2.tools.Console
How do I call one batch file from another without using the calling batch files path?
Explanation
It seems that when they are executed from the batch file two
directories up they are for some reason using the relative path of the
calling batch file. Is my assumption correct?
Yes your assumption is correct. Calling a batch file will not change the current working directory. The main batch file will be found because you are providing the correct relative path, but all the other relative paths will be seen from the perspective of your current working directory, not from the directory that contains the main batch file.
%~dp0 is your friend, it yields the drive letter and path to the batch file containing that character sequence. Use it as a basis for relative paths and your batch files will work no matter who calls them from where.
Example:
Fictitious h2.bat that won't work:
#echo off
h2.exe start
Working h2.bat:
#echo off
"%~dp0\h2.exe" start
See What does %~dp0 mean, and how does it work? for more explanations on %~dp0
Try setting the directory:
cd ht\bin\
call h2.bat
cd %HOMEPATH%
REM just reset to where ever you were before.
If that doesn't work, try using the C:// prefix in your path. That might/might not work.
Good Luck!
Suppose current .bat file is running in C drive and you want to run .bat file placed in D: directory then in first .bat write.
D:
cd "D:/folder/folder2/"
call batFile.bat
It might be because you don't have permission. M facing the same problem and i found the solution like this -
Right click on your task than properties.
In properties click on General tab and then click on 'User Group or User' and select appropriate user.
Or create a another bat file to call your bat file and schedule that file. you can create the bat file like this -
open Notepad and give your original bat file path and then call bat file with name like -
D:
cd "E:/ABC/FirstJob/main/"
call main_run.bat
Now save this file with .bat extension.
if your bat file is correct, try cmd command as below and hit enter(tried in windows 10):
"\h2.bat"
e.g: "C:\Users..\bin\h2.bat"
I tried :
pushd h2\bin\
call h2.bat
=> It 's okay.

help with windows batch scripting basics - execution and calling a separate executable within the script

Newbie to windows scripting. I need help running the .bat file on the command line so I can test it.
I used Text Document as my editor to create the file (opens up also as Notepad).
I performed file "save as" (ALL FILES). If I open up cmd, I can see the file has a .txt extension (myfile.bat.txt). So if I just type in cmd myfile.bat.txt the editor opens. I am not sure how to execute this correctly.
As for the logic in my batch script, I am basically logging into a remote directory (already created the net mount) and now I want to:
run an executeable file
rename some files.
With some research, I written this so far. I have saved it as a .bat file
# echo off
echo This is a batch file to run an executable and rename some files
pause
--run executable file here, just don't know how to do it
x:
cd x:
rename fileA fileB
Any help, good tips/practice would be great. Thanks.
Type in this command in cmd window:
rename myfile.bat.txt myfile.bat
Now you can run the script by simply invoking:
myfile.bat
or
myfile
(provided there's no myfile.exe or myfile.com in the same directory).
If you need to edit the script further, you can either right click it in Explorer and choose Edit or call the editor from the command window:
notepad myfile.bat
To call a program from the script, simply add its name, if it's in the current directory:
someprogram.exe
or the name with the path, if it's somewhere else:
directory\program.exe
or
d:\directory\program.exe
If the name or the path contain spaces, be sure to enclose the entire name & path string in double quotes:
"d:\directory\program name.exe"
you can just type the full name of the program
eg
"c:\program dir\program.exe"
or you can add the program directory to your path environment variable
set PATH=%PATH%;"c:\program dir"
and just type the program name
program
you can also edit your PATH variable in windows http://support.microsoft.com/kb/310519
NOTE: When you save the file in notepad, you want to save it as filename.BAT and select All Files from the second dropdown. If you don't it still gets saved as a .TXT.
A couple of command to consider:
CSCRIPT cscript /? in CMD
START http://ss64.com/nt/start.html
If you're doing say a VBSCRIPT use CSCRIPT to start it. If you're trying to execute another BATCH script or an EXE, use START

How to move output file in dos

I would like to create a batch file which will move the output file of a custom command "mdmg C:\source i5". I must execute this command from the C:\home directory where the mdmg.cmd resides.
This command converts the any file in the source dir and creates an output files in the C:\home folder.
However I want to move the output files to another folder autometically, lets say C:\test.
can it be done in a batch script?
Thanks in advance.
bla.bat
move c:\home\* c:\test
What is the problem ? DOS has a move command. Or you could simulate that with a copy and delete if move is unavailable for some reason.
You could save yourself the trouble of the batch using CMD redirects. Just paste the following behind the mdmg.cmd command.
> "C:\source i5\output.txt"
Basically the CMD interpreter will execute the command(s) in mdmg.cmd, and then redirect the output of the commands to print in output.txt. This way you don't have to call another batch. Another cool thing about doing it this way is that if the output file does not exist at the specified path, cmd.exe will make it for you.

Resources