I have a batch script that that uses mdpdf. I use the command mdpdf FILE_NAME.md FOLDER/DIFFERENT_FILE_NAME.pdf, and after that I have a few more batch commands. My script looks like this:
mkdir folder
mdpdf filemd.md folder\filepdf.pdf
echo "table{border-collapse:collapse;}table,td,th{border:1px solid black;}" > table.css
pandoc -s filemd.md -c table.css -o ./folder/filehtml.html
del table.css
copy filemd.md export\filemd.md
cd folder
powershell Compress-Archive * Folder-Zip.zip
move Folder-Zip.zip ..\Folder-Zip.zip
cd ..
rmdir /Q /S folder
but after it's done I am left with a foler "folder" and inside a file named "filepdf.pdf". I tried without the mdpdf filemd.md folder\filepdf.pdf and it ended up with a "Folder-Zip.zip" with inside it "filemd.md" and "filehtml.html". What can I do, so I am left with a zip file named "Folder-Zip.zip" with inside of it "filemd.md, filepdf.pdf and filehtml.html"?
Related
I have multiple folders inside N:\working.
N:\working\1
N:\working\2
N:\working\3
I want to RAR compress them all individually on 64-bit Windows.
Here is the code I have so far:
#ECHO OFF
CD N:\working
SET rar_executable=C:\Rar.exe
ECHO Using WinRAR executable: %rar_executable%
ECHO.
%rar_executable% a -r -ep1 -m0 "Test.rar"
pause
It produces the file Test.rar containing all three folders. But I want to archive the three folders into the archive files 1.rar, 2.rar and 3.rar.
That task can be done with a batch file containing only a single command line.
#for /D %%I in ("N:\working\*") do #"%ProgramFiles%\WinRAR\Rar.exe" a -cfg- -ep1 -inul -m5 -r -- "%%I.rar" "%%I\"
The same command line for usage in a command prompt window without using a batch file:
for /D %I in ("N:\working\*") do "%ProgramFiles%\WinRAR\Rar.exe" a -cfg- -ep1 -inul -m5 -r -- "%I.rar" "%I\"
There is no # left to for as that would be completely useless on running this command line in a command prompt window. # left to Rar.exe with full qualified file name is removed to see the command line output by cmd.exe when a new archive file creation starts.
FOR searches in specified directory N:\working for non-hidden subdirectories and assigns the full qualified directory name to loop variable I before executing Rar.exe for this subdirectory.
Rar.exe adds (a) recursively (-r) all directories and files in the subdirectory found by FOR to a RAR archive file with name of the current subdirectory and file extension .rar created in the specified directory N:\working using best compression (-m5) without any output to console window and ignoring all errors (-inul) which could occur during folder compression. The standard configuration is ignored (-cfg-) on compression. The name of the compressed subdirectory with its path is not added to the RAR archive file (-ep1 and folder to compress ends with a backslash).
Open a command prompt window, run for /? and read the output help explaining option /D (directory search).
Open text file Rar.rxt in program files folder of WinRAR with a double click which is the manual of Rar.exe explaining the command a and the switches used here.
This task could be also done with WinRAR.exe using a profile created before with starting WinRAR.exe with the profile name as only option on the command line stored in a shortcut file. This solution would not open a console window because of WinRAR.exe is a Windows GUI desktop application.
try this script as a .bat file which will compress each folder as a RAR file within the current directory and also will show some additional detail which is very useful while compressing a large size of data.
.Bat File Script
#echo off
#for /D %%I in (".\*") do echo started at %date% %time% compressing... "%%I" && #"%ProgramFiles%\WinRAR\Rar.exe" a -cfg- -ep1 -inul -m5 -r -- "%%I.rar" "%%I\"
echo "Completed Successfully !!!"
pause
Sample Outout
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
Using the WinRAR command line (C:\Program Files\WinRAR\Rar.exe), what I'm trying to do is compress a single folder in a main folder (C:\Users\%username%\desktop\mainFolder) to a new folder (C:\Users\%username%\desktop\newFolder) and delete the single folder after compression in the main folder.
So that ONLY the first subfolder is compressed every time I start the .bat
C:\Users\%username%\mainFolder
singleFolder1
singleFolder2
singleFolder3
So far that does only work for all folders which are in the main folder
c:
cd \Users\%username%\Desktop\newFolder
"C:\Program Files\WinRAR\Rar.exe" a -ep1 -mt5 -m1 -v50M -r "!_RndAlphaNum!" C:\Users\%username%\Desktop\mainFolder\
The !_RndAlphaNum! is because I use a code at batch start that generates random names for the .rar archives.
That is similar to Using a loop to rar multiple subfolders in a main folder and can be therefore easily achieved with
#echo off
for /D %%F in ("%USERPROFILE%\mainFolder\*") do (
"%ProgramFiles%\WinRAR\Rar.exe" m -ep1 -mt5 -m1 -v50M -r "%USERPROFILE%\desktop\newFolder\%_RndAlphaNum%" "%%~F"
goto Done
)
:Done
The command goto Done results in breaking FOR loop after processing first directory and continue the batch job below label Done.
Again command m is used instead of a to archive and then delete all files and folders packed into the archive file created directly in the destination folder.
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"
My computer's OS is win7
I want to use a .bat file to open a new shell, then run script in a new shell
this shell is OSGeo4W Shell
it is located in "C:\Program Files\QGIS Dufour\OSGeo4W.bat"
so I used
cd "C:\Program Files\QGIS Dufour\"
OSGeo4W.bat
cd "C:\Users\tony\Downloads\11\computingArea"
ogr2ogr -f CSV my_csv Grid.dbf
ogr2ogr -f CSV csv Grid.dbf
addcenter.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/Grid.csv
copy Grid.shp my_dir
copy Grid.shx my_dir
rd my_csv /s /q
rd csv /s /q
ogr2ogr -clipsrc t.shp test.shp ./my_dir/Grid.shp
rd my_dir /s /q
ogr2ogr -f CSV wellcsv welllocation.dbf
ogr2ogr -f CSV csv test.dbf
computingArea.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/test.csv
rd csv /s /q
rd wellcsv /s /q
move test.shp my_dir
move test.shx my_dir
del test.dbf /q
But, this script only open OSGeo4W Shell
Please tell me how to solve this problem.
i had similar problem, and i managed to resolved like this: I had a script file called script.bat with various python and ogr functions. In separate bat file i typed:
call "C:\Program Files\QGIS 2.14\OSGeo4w.bat" start cmd.exe /k script
pause
This bat file calls inital script.bat in OSGeo4W Shell.
*note1: Both bat files must be in same directory.
**note2: In your case script.bat will have content:
ogr2ogr -f CSV my_csv Grid.dbf
ogr2ogr -f CSV csv Grid.dbf
addcenter.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/Grid.csv
copy Grid.shp my_dir
copy Grid.shx my_dir
rd my_csv /s /q
rd csv /s /q
ogr2ogr -clipsrc t.shp test.shp ./my_dir/Grid.shp
rd my_dir /s /q
ogr2ogr -f CSV wellcsv welllocation.dbf
ogr2ogr -f CSV csv test.dbf
computingArea.exe
ogr2ogr -f "ESRI Shapefile" my_dir ./csv/test.csv
rd csv /s /q
rd wellcsv /s /q
move test.shp my_dir
move test.shx my_dir
del test.dbf /q
and separate bat file will be:
call "C:\Program Files\QGIS Dufour\OSGeo4w.bat" start cmd.exe /k script
and both bat files must be in directory with data (C:\Users\tony\Downloads\11\computingArea). I hope this will work, it worked for me!
You could try this:
start cmd /K echo Hello world!
It definately works on windows XP, the /K runs the specified command but retains the new cmd prompt! Hope it is useful!
You could try this if you don't want the cmd prompt to remain:
start cmd /C echo Hello world!
I am afraid I haven't used OSGeo4W I just assumed it was using windows. Regardless I'll list some options which work on Linux depending on the shell followed by an example using Cygwin. Maybe it will help..
-> You can use gnome-terminal
Gnome-terminal is a terminal emulation application and the -x specifies you want execute the subsequent command:
gnome-terminal -x ./script.sh
-> Background Process in the current terminal
You can background the first processes by adding an ampersand (&) to the command line or pressing Ctrl+Z when it is running. You then enter "bg" to let the process continue.
-> You can use xterm and background the process:
xterm -e ./myProcess3 &
-> An example using cygwin
cygstart /bin/bash -li
Hope I got all that right, I actually can't test it right now (new windows build PC).
This is a good question. I'm also trying to do this. You can try putting the rest of the script in another .bat file or in a .sh file and pass this file as an argument to OSGeo4W.bat. The script would be something like this:
cd "C:\Program Files\QGIS Dufour\"
OSGeo4W.bat script_inside_the_shell.bat
or
cd "C:\Program Files\QGIS Dufour\"
OSGeo4W.bat sh script_inside_the_shell.sh