Im trying to make a batch file that process multiple image files.
The files are named P_1316_0001.png P_1316_0002.png P_1316_0003.png etc..
LETs sqy P_1316 is VARSESSION)
thanks to the ImageMagick program i can convert an image directly with batch.
Basically what i want to do is :
Create a variable that would increment until there is no more file to convert in the folder. Comvert the file from png to jpg (convert %VARSESSION%%i%.png %VARSESSION%%i%.jpg) assuming that i is 0001
Well i hope you can help me.
i thank you
Daniel
You're being a little restrictive with your question, but to suit the precise parameters you've specified,
SETLOCAL ENABLEDELAYEDEXPANSION
for /l %%i in (10001,1,19999) do (
set numb=%%i
ECHO if exist %varsession%_!numb:~1!.png convert %varsession%_!numb:~1!.png %varsession%_!numb:~1!.jpg
)
ENDLOCAL
But there are much better ways, such as
for /f %%i in ('dir /b /a-d %varsession%_*.png') do (
ECHO convert %%i %%~ni.jpg
)
Assuming that all files matching %varsession%_*.png are to be processed.
Note: keyword ECHO inserted to SHOW what the batch proposes to do. Remove the ECHO to actually perform the action
Related
My code stops at line 3 in the .dat file ,but when i save the .dat file it reads all the lines and work properly why this happening and what to do??
this is code my data contain Latina characters and symbols.
#ECHO Off
SET "sourcedir=D:\yyyyy\Orgin_file_Ma\MA_SMS"
SET "destdir=D:\llllll\STG_file_Ma"
FOR %%f IN ("%sourcedir%\*.dat") DO > "%destdir%\%%~nf.txt" (
FOR /f "usebackqdelims=" %%a IN ("%%f") DO (
set Typ=SMS
ECHO %%a^|!Typ!
)
)
This is effectively the same question you asked yesterday.
An answer cannot be provided unless you change your code to something that works; try this:
#ECHO OFF
SET "SOURCEDIR=D:\yyyyy\Orgin_file_Ma\MA_SMS"
SET "DESTDIR=D:\llllll\STG_file_Ma"
SET "TYP=SMS"
FOR %%F IN ("%SOURCEDIR%\*.dat") DO FOR /F "USEBACKQ DELIMS=" %%A IN ("%%F"
) DO >"%DESTDIR%\%%~nF.txt" ECHO %%A^|%TYP%
After confirming the structure of the above script is correct, add it to your question above by way of the edit facility and provide much more information on those dat files.
Depending upon those dat files it is likely that ECHO may not be the correct command to use.
Thank you for your helpful answers i learned a lot,i solved my problem by using Powershell instead of batch.
I have hundreds of csv files . csv files are stored in folders and sub folders . I want to search fifty csv file whose file names have been determined , for example 1.csv , 2.csv , 3.csv , ... , 50.csv . very troublesome if I searched one by one using the Windows search tool . I would like if the files are found , save in the folder named FOUND . please help to overcome this problem by using the batch programming / bat ? thank you very much
There's a number of approaches one can take, depending on how much automation you require... To help you get started, you may want to look at this it helped me (and indeed continues to do so) when I started learning batch. Furthermore I will provide one possible template for achieving your objective, as I have interpreted it. Perhaps it is not the most elegant or efficient method, but it introduces a number of batch commands that you may or may not have encountered, which in turn may help you develop your own method.
#echo off
setlocal enabledelayedexpansion
echo Please enter a drive letter:
set /p "drive=>"
echo Please enter a search string:
set /p "searchstring=>"
echo %searchstring%>search.txt
set /p search=<search.txt
set /a suffix=0
echo.>>search.txt
:LOOP
for /f "tokens=*" %%i in ("search.txt") do (
set /a suffix=suffix+1
set seq=%search% !suffix!
echo !seq!>>search.txt
)
if !suffix! leq 49 goto LOOP
for /f "tokens=*" %%i in (search.txt) do (
for /f "tokens=*" %%j in ('dir /b /s /a-d %drive%:\"%%i.csv" 2^>nul') do (
if not exist "%~dp0\found" md "%~dp0\found"
move /y "%%j" "%~dp0\found\%%~nxj"
)
)
pause
This is not intended as a definitive solution, though you may find it answers your original query/request. All the best.
Here's another working solution for you..
#ECHO OFF
SETLOCAL EnableDelayedExpansion
REM First Set your directories input and output
SET InputDir=C:\Directory to your CSV files\
SET OutputDir=C:\Directory to your CSV files\FOUND
REM check if the FOUND directory exist, if not, then create it.
IF NOT EXIST OutputDir (
mkdir %OutputDir%
)
REM Grab a scan of the input directory and save it to a temporary file list.
Dir /a /b %InputDir%>"%OutputDir%\Found.txt"
REM Set the files you would like to find.
SET "File1=1.csv"
SET "File2=2.csv"
SET "File3=50.csv"
REM The loop, to process the matching file(s).
FOR %%A IN (%File1%,%File2%,%File3%) DO (
FOR /F "usebackq" %%B IN ("%OutputDir%\Found.txt") DO (
IF %%A==%%B (
copy "%InputDir%\%%A" "%OutputDir%\%%A"
)
)
)
REM Clean up the temp file list.
DEL "%OutputDir%\Found.txt"
Make note, I didn't add quotes to the Input and Output variables, but instead added quotes to the copy portion of the code to compensate for white spaces in your directory path. I tried to keep it simple, so you could follow the logic of how it processed what you are looking for, you can now modify this to your liking.. Have fun. Cheers!
I want to convert this GIF file in same folder
muz-171669-JA_fig_10.gif
muz-171669-JA_fig_11a.gif
In this pattern:
muz is convert to muz12345
Here in numeric value "171669" only last 4 digit must be taken means:
"171669" is convert to 1669
fig_10 is convert to this value f010.
Sometime name is like this fig_11a so in that case it should be convert into this way:
f11a
There are hundreds of gif files with such filename
with suffix fig_01 till fig_999.
And it should be convert like this:
suffix f001 till f999
Sometimes fig_11a suffix occur in that case it should be convert like this f011a.
The output of the following :
muz-171669-JA_fig_10.gif
muz-171669-JA_fig_11a.gif
must be like this:
muz123451669f010.gif
muz123451669f11a.gif
I am doing this manually and it takes lots of my time.My friend told me that this is possible using batch extension. but i dont have must knowledge in batch command.
Can anyone help me out? its project requirement.
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir\t w o"
FOR /f "tokens=1-7delims=-_." %%a IN (
'dir /b /a-d "%sourcedir%\muz-*-*_*_*.gif" '
) DO (
IF "%%g"=="" (
SET "num2=%%b"
SET "fig=%%d"
SET "num3=00%%e"
ECHO(REN "%sourcedir%\%%a-%%b-%%c_%%d_%%e.%%f" "muz12345!num2:~-4!!fig:~0,1!!num3:~-3!.%%f"
)
)
GOTO :EOF
This should process the files appropriately. You would need to change the setting of sourcedir to suit your circumstances.
The required REN commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(REN to REN to actually rename the files.
I'm trying to write a Windows batch file to rename a set of files based on their original name. What I essentially want to do is find text within a file name and replace it with other text.
For example, if the files had the naming structure "Family Christmas 001.jpg" I might want to change it to "Photos - Xmas 001.jpg". ie replace "Family Christmas" with "Photos - Xmas". This is just an example.
I've found a piece of code from a user of this site, dbenham, that does almost exactly what I'm after. In this example he's replacing "120x90" in a filename to "67x100"
Here's the code:
#echo off
setlocal enableDelayedExpansion
for %%F in (*120x90.jpg) do (
set "name=%%F"
ren "!name!" "!name:120x90=67x100!"
)
Can anyone help me adapt this code to make it handle spaces in the file name?
Thanks
All you're missing is quotes within the FOR statement - to follow your example:
#echo off
setlocal enableDelayedExpansion
for %%F in ("Family Christmas*.jpg") do (
set "name=%%F"
ren "!name!" "!name:Family Christmas=Photos - Xmas!"
)
I am trying to achieve some file control with batch processing.
The base idea is a text file is supplied which contains a list of files and folder paths.
What I then need to do is is move these names files to another location referencing the same folder structure. The folder paths also vary some can be 2 deep others up to 4.
The reason for batch is that it can be hundreds of files at a time thus making manual processing time consuming and hard.
An example of the text file input is:
copier\spc240\parts.cat\M095_M096_CHN_V1.05.pdf
copier\spc240\parts.cat\M095_M096_NA_V1.06.pdf
copier\spc240\parts.cat\M099_M100_NA_V1.10.pdf
copier\spc240\parts.cat\M100_CHN_V1.10.pdf
options\df3090\D779_21_V1.01.pdf
options\pb3190\D747_27_V1.00.pdf
Below is what I have managed to do so far:
#echo off
set "file=deletes.txt"
set /A i=0
for /F "usebackq delims=*" %%a in ("%file%") do (
set /A i+=1
call set array[%%i%%]=%%a
call set n=%%i%%
)
for /L %%i in (1,1,%n%) do (
echo|set /p="move %%array[%%i]%% moved\%%array[%%i]%%">>Test.txt
echo.>>Test.txt
)
echo pause>>Test.txt
rename Test.txt RunMe2Move.bat
pause
What this currently does for me is make a batch file that could be run seperately, however this is where I stumble down. This errors as the destination folders do not exist and I am not familiar enough with arrays in batch to split the text lines to enable me to use the mkdir for the missing folders or trim the file names.
In essence I am trying to get the following lines of code either processed or output (using copier\spc240\parts.cat\M095_M096_CHN_V1.05.pdf as example) for each line in the text file.
mkdir moved\copier\spc240\parts.cat\
move copier\spc240\parts.cat\M095_M096_CHN_V1.05.pdf moved\copier\spc240\parts.cat\
Ultimately I am trying to get all of this done in one file if possible, the output is just there so I can check things through.
Can anyone help?
for /f "delims=" %%a in (%file%) do (
SET "fpath=%%~a"
SETLOCAL enableDelayedExpansion
SET "fpath=!fpath:%%~nxa=!"
md "moved\!fpath!"
move "%%~a" "moved\!fpath!"
ENDLOCAL
)