Solved

VBS file - No output

Posted on 2013-01-22
7
521 Views
Last Modified: 2013-01-22
I am working on a bat file that swaps around columns in a file and adds 1 to one column in the file.  The code that I have written is processing without error and producing a file, but the file has no data in it.  I can't figure out if I have a problem in my set statements for each line or if I have a problem in my for loop that creates the file.  Can someone help me?
Thanks,
Cindy
file-translator.txt
0
Comment
Question by:vdixon79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 55

Accepted Solution

by:
Bill Prew earned 400 total points
ID: 38805652
I saw and fixed a couple of problems, see if this works any better.

@echo off
setlocal enabledelayedexpansion

cd /d "C:\Program Files (x86)\TMW Systems, Inc\ImporterServiceConsole\Bat files for CSO to get HM163 and HM144"


if exist EJPope_pretranslated.txt del EJPope_pretranslated.txt
if exist EJPope_translated.txt del EJPope_translated.txt


copy "\\192.168.41.35\c$\CSO\*.xls" "C:\Program Files (x86)\TMW Systems, Inc\ImporterServiceConsole\Bat files for CSO to get HM163 and HM144\EJPOPE_pretranslated.txt"


echo Step 1 >> "%temp%\MyBatch.log"


set InFile=EJPope_pretranslated.txt
set outFile=Fuel Inventory 178.txt

if exist "%outfile%" del "%outfile%"
if exist "Fuel Inventory 178.txt" del "Fuel Inventory 178.txt"


(set ImportDelim=	)
set ExportDelim=;
set /a LineCount=0

for /f "usebackq skip=1 tokens=1-10 delims=%ImportDelim%" %%a in ("%InFile%") do (
	
	if not "%%b"=="" (
		set /a LineCount +=1
		if "%%c"=="1437" set Line[!LineCount!]=%%c%ExportDelim%%d+1%%ExportDelim%%%f%ExportDelim%%%g%ExportDelim%%%h%ExportDelim%0%ExportDelim%0%ExportDelim%%%j%ExportDelim%%%e%ExportDelim%
		if "%%c"=="1428" set Line[!LineCount!]=%%c%ExportDelim%%%d%ExportDelim%%%f%ExportDelim%%%g%ExportDelim%%%h%ExportDelim%0%ExportDelim%0%ExportDelim%%%j%ExportDelim%%%e%ExportDelim%
		)
)

for /l %%i in (1, 1, %LineCount%) do (
	set Line=!Line[%%i]!
    echo !Line!>> "%OutFile%"
) 

if exist EJPope_pretranslated.txt del EJPope_pretranslated.txt 
copy "C:\Program Files (x86)\TMW Systems, Inc\ImporterServiceConsole\Bat files for CSO to get HM163 and HM144\Fuel Inventory 178.txt" "\\192.168.41.35\c$\CSO Outgoing\*.*"

Open in new window

~bp
0
 

Author Comment

by:vdixon79
ID: 38805828
Bill,
Thank you so much.  I could not figure out that last piece and the internet was very little help.  

Last thing not working, I thought I could just add a 1 to %%d  (%%d+1), but the result came back blank. The adding of 1 to d is only when "%%c"=="1437", so I can't add it all the time.  Do I have my syntax wrong or is this not the way I can do it?
Cindy
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
ID: 38805992
You can't do addition like that sorry, you would need to put it into a temporary variable using set /a to do the maths:

e.g.

set /a num=%%d + 1
then use !num! instead of %%d in the next line.

Steve
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vdixon79
ID: 38806022
Thanks Bill and Steve!

You have made my day.  
Cindy
0
 

Author Closing Comment

by:vdixon79
ID: 38806030
Thanks again for Experts like you being willing to help those of us who aren't.
Cindy
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 38806580
Welcome, glad that was helpful.

~bp
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question