I have a old batch script from nt/xp that runs from Context Menu. What it does is when I select a folder and run cmd it will create a temp folder in the active folder i right clicked in. Then will run a program to convert all the tiff's in the original folder and output the new images in the temp folder. New that I using windows 7, I'm having problems getting the CMD.exe to open in the working folder. when I use the script and right click it goes to /windows/system32 and not the folder I click on.
here are the reg file and batch to show what I want to do:
REG file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\BW Comp/OV]
#="B&W Compress/OV"
[HKEY_CLASSES_ROOT\Folder\shell\BW Comp/OV\Command]
#="C:\\Program Files\\ISRU\\bin\\bwcov.cmd"
BATCH file:
mkdir temp
FOR %%j in (*.tif) do mr_file -T -S 128 -C j -Q 3 -K g %%~nj.tif temp\%%~nj.tif
This was a very simple setup but now with window 7 I can't get it to use the working folder in the batch when making DIR or processing images.
Try this batch file:
#echo off
pushd "%~1"
mkdir temp
FOR %%j in (*.tif) do mr_file -T -S 128 -C j -Q 3 -K g "%%~nj.tif" "temp\%%~nj.tif"
popd
if mr_file is a batch file also then it will need call before the name.
This batch file should work in the SENDTO menu also
but the registry file looks odd to me.
Foxidrive, I tried your suggestion and that work creating temp folder using folder I right clicked on.
Here are the new files.
Batch File (I used a new program called make_pry instead of mr_file:
#echo on
pushd "%~1"
Title %~f1
mkdir temp
FOR %%j in (*.tif) do make_pyr %%~nj.tif -TIFF -JPEG -QFACTOR 97 -tile 128 -out temp\%%~nj.tif
And Reg File (this file was also changed and was the only way I could get it to mkdir command to work in batch. If I remove the %1, /a or /c it will not work:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\BWCOV]
#="BW Compress OV"
[HKEY_CLASSES_ROOT\Folder\shell\BWCOV\command]
#="cmd.exe /a /c Inpho_bwcov.cmd %1"
Related
I'm new to this cmd/FTP command. I would like to create a new folder at my local directory using today's date and connect to FTP to download the specific file to the newly created folder. If I manually type in command one by one at cmd, it has no issue. But when I use a batch file to run, my command stopped at FTP.
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4"_"job%
mkdir C:\%name%
cd C:\%name%
ftp
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget -i *.*
I did try to separate my command to two batches;
1. folder creation
2. FTP download but the file downloaded didn't go into the folder I created. the downloaded file went to C:\Document & Settings.
main batch file
#echo off
call rename.bat
ftp -i -s:ftp.txt
rename.bat
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd c:\%name%
ftp.txt
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget *.*
close
Another method I try is using '!' when in FTP environment, then create a folder then exit back to FTP environment. This method again doesn't work with the batch file. Please help
It seems that with command extensions enabled, the working directory set by a child batch file is lost, then the batch file exits.
I'm not sure how to solve it, but you actually do not need the rename.bat file to be a separate file. This "main batch file" should work:
#echo off
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd /d c:\%name%
ftp -i "-s:%~dp0\ftp.txt"
Also note the /d added to cd. Without that your batch will not work when started from another drive. You also have to use %~dp0 to refer to the batch file folder for the ftp.txt. As at the time ftp is called, you have changed to the target directory.
You possibly do not even need the command extensions to be enabled. So simply removing the setlocal enableextensions might solve the problem too. Though you still need the %~dp0 and /d.
I've decided to post this, although similar to the answer given, there are a couple of differences.
It creates the text file, then deletes it, (this keeps everything more portable).
I have corrected your directory name, (because of a typo).
#Echo Off
Set "Name=%DATE%"
Set "Name=%Name:~-10,2%-%Name:~-7,2%-%Name:~-4%_job"
MD "C:\%Name%" 2>Nul
CD /D "C:\%Name%" || Exit /B
( Echo open 192.168.31.93
Echo *user*
Echo *password*
Echo binary
Echo cd *directory*
Echo mget *.*
Echo close
)>"ftp.txt"
FTP -i -s:ftp.txt
Del "ftp.txt" 2>Nul
Exit /B
I want to drag and drop a file onto a batch file in order to run the below command on it. How do I go about running the command on the dropped file?
PotreeConverter.exe <dropped file> -o C:/output -p index
The path of the file, when you drop it on the BATfile, will be returned as a normal %1 argument.
so :
#echo off
PotreeConverter.exe "%~1" -o C:/output -p index
You can use %* if you drop more then 1 file
Example :
#echo off
for %%a in (%*) do echo [%%a] was dropped on me
pause
Following this easy guide.
Create a batch file test.bat with the contents
#echo off
echo The full path of the file is: %1
pause
Drag any file onto it, you will see that %1 is replaced with the full path for that file in quotes.
Now you know how to execute some command that takes a path to a file as an argument:
#echo off
some_command_that_takes_a_path_to_a_file %1
Working with rsync on a windows machine (cWrsync) and I am syncing a large folder with sub directories to a web server which takes several minutes to complete. But when the user just needs to add a file to a sub-directory I don't want them to have to wait an hour to sync that directory.
My Idea
Add a file into each sub-directory (1_sync.bat) that they can execute when they add or delete a file within that directory. I need the batch file to be able to dynamically tell rsync which directory to sync.. here is the static version:
#echo off
REM Make environment variable changes local to this batch file
SETLOCAL
REM where ti find rsync and related files
SET CWRSYNCHOME=C:\cwRsync
SET HOME=C:\Users\greg\AppData\Roaming
SET CWORLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
"C:\cwRsync\bin\rsync.exe" -v -e 'ssh -i C:\home\greg\.ssh\id_rsa' --delete --recursive --inplace "/cygdrive/z/1CustomerDocs/2017/Client Folder/" "root#domainname.com:/var/storage/customer_files/2017/Client\ Folder/"
In the above example I would like to have Client Folder be a variable that will detect what folder the batch script is actually in so I can just through one of the bat files in every sub directory.
I tried %~dp0 which almost does the trick, but outputs the entire path.. I just need the last two directories.
so if %~dp0 = \SERVER-PATH\Content\1CustomerDocs\2017\Client Folder\
I wish I could cut the last two directories off and have a variable that looks like
2017/Client Folder (but also need one that escapes the spaces for linux)
So the end results would look like
#echo off
REM Make environment variable changes local to this batch file
SETLOCAL
REM where ti find rsync and related files
SET CWRSYNCHOME=C:\cwRsync
SET HOME=C:\Users\greg\AppData\Roaming
SET CWORLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
SET CUST_FOLDER_WINDOWS=*YOUR HELP NEEDED HERE*
SET CUST_FOLDER_LINUX=*YOUR HELP NEEDED HERE*
"C:\cwRsync\bin\rsync.exe" -v -e 'ssh -i C:\home\greg\.ssh\id_rsa' --delete --recursive --inplace "/cygdrive/z/1CustomerDocs/%CUST_FOLDER_WINDOWS%" "root#domainname.com:/var/storage/customer_files/%CUST_FOLDER_LINUX%"
And again, I would need the linux folder to escape spaces.
Thanks for the help!
To be independent from the current dirlevel:
#echo off
Echo current dir %CD%
Echo Batch dir %~dp0
for %%a in ("%~dp0.") Do Set "Parent=%%~nxa"
for %%a in ("%~dp0..") Do Set "Grandparent=%%~nxa"
Echo Last 2 dirs \%Grandparent%\%Parent%
current dir Q:\Test\2017\08\10
Batch dir Q:\Test\2017\08\10\
Last 2 dirs \08\10
Figured it how below
#echo off
REM Make environment variable changes local to this batch file
SETLOCAL
REM where ti find rsync and related files
SET CWRSYNCHOME=C:\cwRsync
SET HOME=C:\Users\greg\AppData\Roaming
SET CWORLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
for /F "tokens=5,6 delims=\" %%a in ("%0") do (
"C:\cwRsync\bin\rsync.exe" -v -e 'ssh -i C:\home\greg\.ssh\id_rsa' --delete --
recursive --inplace "/cygdrive/z/1CustomerDocs/%%a/%%b/"
"root#domainname.com:/var/storage/customer_files/%%a/%%b/"
)
My scheduler will run every 15 mins and I don’t want to copy the same file again.
I have the script below in a batch file running in the task scheduler:
cd C:\Program Files (x86)\WinSCP
FOR /R C:\Utils\TRASACTION\ICP %%f IN (*.LOG) DO TYPE NUL>%%f
Winscp.com /script=C:\Utils\TRASACTION\ICPS\download.txt >> C:\Utils\ICPS\lowe.log
set CURRENT_DATE=%date:~10,4%%date:~4,2%%date:~7,2%
xcopy C:\Utils\TRASACTION\Accounting_file\%CURRENT_DATE%\ACCOUNTING_FILE_* Y:\Transactions\In >> C:\Utils\TRASACTION\ICPS\lowe.log
exit
in line 3 that download.txt contains the below script
option echo off
option batch on
option confirm off
open sftp://icps:xxxxxxxxx#11.111.111.111
lcd "C:\Utils\ TRASACTION\ICPS"
cd /Out/1.ACCOUNTINGFILE
get %TIMESTAMP#yyyymmdd% C:\Utils\ TRASACTION\Accounting_file\
exit
I would like to insert a check in the script when the folder is available then proceed to the copy or else exit.
Or is there another way not the copy the file from the folder that has been already copied to the directory in below line?
(xcopy C:\Utils\TRASACTION\Accounting_file\%CURRENT_DATE%\ACCOUNTING_FILE_* Y:\Transactions\In >> C:\Utils\TRASACTION\ICPS\lowe.log
Thanks for your help.
I am trying to download a chunk of files from an application. The shell command for it is 'go filename download'.
I have a text file containing all the filenames I have to download. All I want to do is to run a script/command such that when the above command is executed
1. the filenames are picked up from the textfile & executed using the above command
2. existing files/unavailable files are skipped
3. the process then continues with the next files in the list
So far I have this idea of using an operator like go $ download & then feed the operator with the text file containing the filenames list. Thanks in advance.
For Windows, you can use for /f to process the file and create a command from it. The following script supergo.cmd shows how this can be done:
#setlocal enableextensions enabledelayedexpansion
#echo off
for /f "delims=" %%f in (list.txt) do (
echo go "%%f" download
)
endlocal
The following transcripts shows it in operation:
C:\Pax> type list.txt
file1.txt
file number 2.txt
another file.jpg
C:\Pax> supergo
go "file1.txt" download
go "file number 2.txt" download
go "another file.jpg" download
If you're using a shell like bash, you can use sed to create a temporary script from the input file then run that:
#!/bin/bash
sed -e "s/^/echo go '/" -e "s/$/' download/" list.txt >/tmp/tempexec.$$
chmod u+x /tmp/tempexec.$$
. /tmp/tempexec.$$
rm -rf /tmp/tempexec.$$
This puts an echo go ' at the start of each line, a ' download at the end, then marks it executable and executes it.
In both cases (Windows and bash), remove the echo to get it to do the real work.