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.
Related
I have the following batch file HERE
It searches for the line that contains...
[/Script/MyGame.Mode]
Then it creates a new line and adds...
RedirectReferences=(PackageName="%Package%",PackageURLProtocol="%PackageURLProtocol%",PackageURL="%WebAddress%/%Package%%Ext%",PackageChecksum="")
It works unless the original file contains spaces after each line. If there are no spaces it works perfect.
Is there an easy way to clear out all the spaces in the original file before it searches, copies and writes the new line in a new file?
Or is there a better way to do this overall. Sorry but I'm not knowledgeable at batch files yet. Thanks for any help given.
I figured it out. I was able to clear the spaces from the original file with the code below before running the copy and adding the new line.
I changed some file names then ran the code below before I'm checking the file and writing new line.
I had to show some code from my other bat to show you the file name changes. Once you combine everything together in one bat it works fine.
:CLEARWHITESPACE
for /F "eol=; tokens=1 delims=; " %%I in (Game.txt) do (
set /a count+=1
if !count! leq 10 echo %%I>>game.temp.txt
)
:SHOWLINE
set NewURL=RedirectReferences=(PackageName="%Package%",PackageURLProtocol="%PackageURLProtocol%",PackageURL="%WebAddress%/%Package%%Ext%",PackageChecksum="")
pause
:WRITENEW
set inputfile=game.temp.txt
set outputfile=game.temp2.txt
(for /f usebackq^ delims^=^ eol^= %%a in ("%inputfile%") do (
echo %%a
if "%%~a"=="[/Script/MyGame.Mode]" call echo %%NewURL%%
))>>"%outputfile%"
So im working on a batch file that can Extract certain lines of text from a massive number of txt files. I had it working fine inside 1 folder but I needed it to be recursive so I changed it up a bit, and It no longer Outputs anything to a text file
for /r %%Z in (*.as) do (
SET /a count=0
set /a non_eng=0
echo z = %%Z
pause
for /F "eol=; tokens=1,2 usebackq delims=(" %%A in ("%%Z") do (
set /a count+=1
if /i %%A==texte echo !count!=%%A(%%B
) > "%%Z.txt"
Echo Writting To File %%Z.txt
pause
if exist "%%Z" echo LC_!count! >> "%%Z.txt")
This Line No longer works
) > "%%Z.txt"
But if I change it to >> it works fine... Problem Is it doubles up the copied text each time...
Working version (just doesn't delve into directories)
PS: I Worked around this issue but Im still unsure as to what caused the problem in the first place at the very least I believe I should have been geting at least one line of correct output to the file.
Your working code has the redirection placed at the for loop that iterate the files, not the for /f that reads them. In this way there is one open/write/close on the log file for each file being processed, with all the data echoed inside redirected to the output file.
But in the non working version, you have the redirection at the for /f that reads the files. Now you have a open/write/close operation for each of the lines of the file being processed. And, as the redirection is >, only the last execution of the for /f is saved in the file.
The simplest way to avoid it is to enclose the inner for loop in parenthesis and redirect this block
(
for /f .... %%A in (...) do (
....
)
) > "%%Z.txt"
I am trying to write a batch file that will loop through command-line parameters, test whether each is a valid filename, and if so, set two variables. (It will also do more than this, but one question at a time seems best.)
There is a lot of advice out there about this kind of question, but after many hours, I still can't make it work. I've tried a dozen variations on the basic idea below (which tries to set the path and filename.extension from the parameter if the file exists.
setlocal EnableDelayedExpansion
echo on
FOR %%a IN (%*) DO (
if exist %%a set VDOSPATH="%~dp1"
if exist %%a set VDOSFILE="%~nx1"
echo !VDOSFILE! !VDOSFILE!
)
Basically, everything about this is wrong. It sets the variables whether or not the file exists, and it doesn't seem to loop through the parameters, but keeps setting the same variable. I'm trying it with these parameters (where the second is a file that really does exist)
a_parameter c:\pathto\existingfile.ext another_parameter
I'll be very grateful for any help with this.
Try this:
#echo off
setlocal EnableDelayedExpansion
FOR %%a IN (%*) DO (
if exist %%a set VDOSPATH="%%~dpa"
if exist %%a set VDOSFILE="%%~nxa"
echo(!VDOSPATH! !VDOSFILE!
)
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
I know this question is asked many times, but I didn't get the answer for what I am searching.
I want to replace a pattern using windows .bat file.
I know how to replace X with Y.
But I am trying to replace say installPath with C:\Programfiles\Install\.
Here, I am facing issues as the new value string contains \ i.e special character.
Please let me know how I can replace this.
This works fine for me
set p=installPath
set p=%p:installPath=C:\Programfiles\Install\%
echo %p%
Followinf script will find the string in the file and replace with another string.
EX. "installPath" will be replaced with "C:\Programfiles\Install"
#echo off
for /f "usebackq tokens=*" %%a in ("test.txt") do call :Replace "%%a"
del "test.txt"
rename "newfile.txt" test.txt
exit /b
:Replace
set str1=%~1
set str1=%str1:installPath=C:\Programfiles\Install%
echo.%str1%>>"newfile.txt"
exit /b
Perhaps this tool might help you:
http://sourceforge.net/projects/fart-it/
This should work... By the way, this is my first post on this website.
The following uses delayed expansion so that you have two different 'variable symbols' to play with:
setlocal enabledelayedexpansion
set iPath=installPath
set input=C:\Programfiles\Install\
set p=!iPath:installPath=%input%!
Hope this helps