Question

Batch file to get certain things into variables, please help.

Asked by: simonprr

Hi,

I have 2 main questions...

1. How to get the size of a file into a variable? in MB preferably.
2. How to get the length (time - minutes:seconds) of a mp3 file into a variable?

I also have an outstanding question open in programming (maybe I should have posted it here) that I have further things that I would like done as much as possible within a batch file or if necessary, command line application that runs from the batch file.

That question is:  http://www.experts-exchange.com/Programming/Q_20857641.html (500 points)

An urgent response would be appreciated & with more points!

Many Thanks :)

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-01-23 at 16:12:11ID20861327
Tags

batch

Topic

MS DOS

Participating Experts
2
Points
500
Comments
40

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Variables in Batch files
    All experts Thanks in advance... I am automating FTP using a batch file. I just want to know how to store the remote server name, remote dir , remote file name in a file and call the file in the batch script and assign the values as variables and run the batch file. Please ...
  2. URGENT!!! Batch Script
    I am trying to create a batch file that will run multiple installs from nested directories. My batch script looks like this: .\setup.exe /s /w /v"iSX_SERIALNUMBER=1016-1414-8997-8997-2968-4069 TRANSFORMS=Acrostan.mst /qn .\601\ac60bap1.exe -s -a "/p Ac60BaP1.msp RE...
  3. Need to setup variables in batch file
    I have worked with batch files for sometime now, but have never had a need for to call variables from within the batch file itself, until now. Most of the time I will call a variable like %date% or %time% or %location% (if location is setup in the system variables on the com...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: dbruntonPosted on 2004-01-23 at 22:17:27ID: 10189918

If you are running Windows NT the first question can be solved.

One of the good experts here can do that.  But not me.  My dos isn't that good.

The second one probably requires the creation of a util to extract that information from the file and I don't think there's a dos command to do that.

 

by: simonprrPosted on 2004-01-24 at 05:49:23ID: 10190882

Yes, I'm running Windows 2000.

Yes, a command line utility to do that would be the best solution.

Thanks for your reply... hoping the good experts come by soon!! :)

 

by: oBdAPosted on 2004-01-24 at 06:37:03ID: 10190972

With Windows NT4/W2k/XP, you usually use the "for /f" command to get some output into an environment variable.
In your case, there are several possibilities. If you pass the name of the file you want the size of as an argument, simply use "%~z1" to obtain the size in bytes. You can use "dir" combined with the for /f, but you need to search the output for the filename because of the junk displayed around the actual filename.
As for the size in MB, the NT shell offers rudimentary calculation as well ("set /a").
Here are examples for both:

====8<----[FileSize.cmd]----
@echo off
setlocal
echo Using %%~z1 to obtain the file size:
set Size=%~z1
set /a SizeKB=%Size% / 1024
set /a SizeMB=%SizeKB% / 1024
echo Size in bytes: %Size%
echo Size in KB: %SizeKB%
echo Size in MB: %SizeMB%
echo Enter "help call" for more options.

echo.
echo Using "for /f" to obtain the file size:
:: *** list the filename, pipe it through "find" to remove the junk:
for /f "tokens=3" %%a in ('dir /-c %1 ^| find /i "%1"') do set Size=%%a
set /a SizeKB=%Size% / 1024
set /a SizeMB=%SizeKB% / 1024
echo Size in bytes: %Size%
echo Size in KB: %SizeKB%
echo Size in MB: %SizeMB%
echo Enter "help for" for more options.
====8<----[FileSize.cmd]----

As for getting the length into a variable, that's rather easy as well in principle, if you have a command line tool that will display this info. If you happen to have a tool, please provide a link or an example output.

 

by: simonprrPosted on 2004-01-24 at 08:55:34ID: 10191679

Thanks! :) I'm little confused about that script. I have put it into a batch file and ran it, doesn't do much, apart from say it's "missing operand" I guess this is cause I have told it what file I want the size of. Which bit do I need to change for this? Could you possibily add a couple of comments to the lines so I can understand what it's doing better?

Unfortunately, I don't have a command line tool that will display the length of the mp3. If one does exist yes this will be very easy, if not if one could be made that will be fine or a VB script or something. Hope you know how to do this.

Thanks for your help.

 

by: oBdAPosted on 2004-01-24 at 09:43:18ID: 10191899

Just save it as filesize.cmd, then run it with the filename as argument.
filesize your.mp3
There's actually not too much to comment on;
"%1" is the first argument that's passed to a batch.
You can expand this in several different ways, not only using "%1"; "%~z1", for example, will expand to the file size of the first argument. Simply enter "help call", and you'll see a complete list of possibilities.
The "/a" argument for "set" allows for simple arithmetic calculations. Enter "help set" for a complete list ...
The "for /f" command will parse some output and put the tokens into variables (enter "help for" for, you know ;). You can specify a command in the brackets, and the output of the command will be parsed accordingly. The command in this case as you would enter it directly is "dir /-c SomeFileName.mp3 | find /i "SomeFileName.mp3". The "/c" argument in the "dir" command suppresses the commas in the file size; this output is then passed to 'find /i "SomeFileName.mp3"', which suppresses the "garbage" in the "dir" output and only leaves the file information we're looking for.
Open a command prompt, then enter first "dir SomeFileName.mp3" (well, replace the "SomeFileName" with an existing file, of course), then enter "dir /c SomeFileName.mp3" (compare the file sizes of the output), then enter "dir /-c SomeFileName.mp3 | find /i "SomeFileName.mp3" to see the final output. The "^" in the "for" escapes the pipe symbol ("|").
Have a look at http://www.robvanderwoude.com for "some" additional samples of batch scripts.

As for the mp3 information: I've looked around a bit, but couldn't come up with a command line tool; even lame only provides encoding, but doesn't display file information. I'm not really into mp3s, so it might well be possible that there's a tool somewhere that does it, or an expert at Programming might who's familiar with the mp3 format might be able to come up with a small program that displays the information.

 

by: simonprrPosted on 2004-01-24 at 11:46:44ID: 10192073

I see. Works fine now. Thanks. Sorry to be a pain, but is there a way of altering this so that it can do all that inside a batch file that I already have that does lots of other things. I've found that if I run "filesize %mymp3%" from inside it, it doesn't return to the original batch file to continue processing other commands. Inside this other batch file I have the mp3 in a variable so would be useful if I could add that code to it so that it all runs from within it.

Does that make sense? Sorry if I haven't explained that very well.

I knew about the for, call and set commands, however didn't understand what the help means. I don't think it explains it very well. It just ends up confusing me further.

Your exactly right, I couldn't find a command line tool either. Hence why I have that other question I mentioned at the start of this one. Unfortunately, I don't seem to be getting many responses to that one :(

PS. Did EE completely screw up earlier? I used to use EE a lot in the past and it always did that all the time then....does it still do that?

 

by: simonprrPosted on 2004-01-24 at 16:18:10ID: 10193251

Or to put it another way, put the size of %mymp3% into %mymp3size% (not using parameters).

 

by: oBdAPosted on 2004-01-25 at 08:06:01ID: 10195625

Yes, seems like it went down. Happens every now and then, but not "all the time".
"mymp3" being the (path and) name of the file in question?
Then use the second possibility from the sample script:

:: *** Put the size in bytes of %mymp3% into mymp3size:
for /f "tokens=3" %%a in ('dir /-c "%mymp3%" ^| find /i "%mymp3%"') do set mymp3size=%%a
:: *** Divide %mymp3size% by 1024*1024 to obtain the size in MB:
set /a mymp3size/=1048576

 

by: simonprrPosted on 2004-01-25 at 10:38:54ID: 10196422

Great! Thanks alot. Well that's certainly part 1 sorted out.

So you don't think I'm gonna have much luck with part 2 without a programmers knowledge? If maybe we could find a command line mp3 player, then maybe set that to play it and output the total time, then use "for" to extract that into a variable?

Pity no-one is responding to my programming question :(

 

by: oBdAPosted on 2004-01-25 at 11:04:37ID: 10196553

You don't necessarily need programmers. "All" you need is some command line program that will (in a command prompt) output the playing time of a given mp3 file. It might already be out there, but I don't have the time to search for it. If you find one, I'll be glad to help you to put this into an environment variable.

 

by: simonprrPosted on 2004-01-25 at 11:34:23ID: 10196690

Yeah I know. I have searched a lot myself, haven't found anything. I'll let you know if I do.

On a slightly different subject, is it possible for a windows application to report back to a batch file?

For example, part of my script runs a ftp program and starts an upload to a certain FTP server. If that FTP server is down I want it to connect to a different one. Trouble is, the ftp program doesn't have this facility. Is there a way of doing this? I expect there is not considering that dos is qutie limited, although surprises me sometimes!

 

by: oBdAPosted on 2004-01-25 at 12:17:49ID: 10196921

There are two ways for that. Most programs return an errorlevel after execution. This is usually 0 if everything went fine, or some higher value if something went wrong.

@echo off
net view \\NotExisting
if errorlevel 1 echo "The execution failed."

If the program doesn't but returns something useful in the output, you can use "find" to search for it. find returns an errorlevel if it didn't find the string specified. In your situation, you can for example use a ping before actually starting the ftp command:

ping -n 1 ftphost1 | find "TTL" >NUL
if errorlevel 1 (
  echo ftphost1 not responding.
  goto TrySecondhost
)

 

by: simonprrPosted on 2004-01-25 at 16:13:26ID: 10197924

I see. Very useful. Thanks

Didn't realise you can put commands in ( ) in batch files... does that just group them together?
So I could do errorlevel 0 to connect?
Also in an earlier batch file you have :: at the start of some lines... is that also a comment command, same as "rem"?

 

by: oBdAPosted on 2004-01-26 at 13:57:30ID: 10204572

With the brackets, you can group some commands together to avoid the "goto".
The errorlevel is a bit tricky: "if errorlevel x" means "if the errorlevel is x *or* *higher*". So if you want to test for errorlevel 0, you have to use "if not errorlevel 1".
The "::" has basically the same effect as a "rem", but it's a bit faster. The interpretes handles is like a label. Have a look at the batch section of th robvanderwoude site, you'll find some useful stuff there.

 

by: simonprrPosted on 2004-01-26 at 16:36:23ID: 10205484

I see, never knew that :) And the "::" bit makes sense now, so really i could just simply use ":"

I have more questions/problems... shall I just post them here and increase the points or do you want me to create new questions? Doesn't seem much point creating new questions when this is a kind of general batch file questions question (if you see what I mean!) However I know I'm extending this question quite a lot so will increase the points.

Checking the ftp sites are available before connecting to perform transfer, by actually connecting first.

if exist tbs.ftp del tbs.ftp
echo open 10.10.10.10 1000 > tbs.ftp
echo USER Bob >> tbs.ftp
echo bob >> tbs.ftp
echo bin >> tbs.ftp
echo literal >> tbs.ftp
echo quit >> tbs.ftp
ftp -n -s:tbs.ftp | find "Connected" >NUL
del tbs.ftp
if errorlevel 1 (
  echo ftphost1 not responding.
  goto TrySecondhost
)

Would that work ok?

Also, I want to write a script to copy a load of different files and different directories, keeping the directory structure, to a certain location. However I want to list the files and directories in a txt file and it to read them from it. Just like a configuration file. For example:

===Backup.txt===
C:\Program Files\Backup
D:\Documents
C:\Windows\Tasks
============

How could I do this? I guess it may use that trusty "for" statement again!

Yes, that Robvanderwoude site is pretty good. Tons of stuff on there, hard to find stuff really. Woud be nice if he gave a better idea of what utilites were on each site really.

Thanks for all your help.

 

by: oBdAPosted on 2004-01-27 at 12:14:06ID: 10212630

You don't need the "del" command at the beginning. If the file exists, it will be overwritten by the "> tbs.ftp" output.
The errorlevel check has to follow directly after the command you want to test; "del" exits with an errorcode as well, which would overwrite the ftp errorlevel.

echo open 10.10.10.10 1000 > tbs.ftp
echo USER Bob >> tbs.ftp
echo bob >> tbs.ftp
echo bin >> tbs.ftp
echo literal >> tbs.ftp
echo quit >> tbs.ftp
ftp -n -s:tbs.ftp | find "Connected" >NUL
if errorlevel 1 (
 echo ftphost1 not responding.
 goto TrySecondhost
)
goto ftpDone
:TrySecondHost
:: *** another go at another host ...
:ftpDone
del tbs.ftp


As for the copying from an ini file, you can use a construction like this:

set IniFile=S:\ome\where\backup.txt
for /f %%a in ('type "%IniFile%"') do call :process "%%a"
goto leave

:: *** Subroutine "process"
:process
:: *** Extract the source file without quotation marks:
set Source=%~1
:: *** Extract *P*ath, *N*ame, and e*X*tension of the source file:
set Target=%~pnx1
:: *** Add the target drive:
set Target=X:%Target%
xcopy "%Source%" "%Target%" <Add your options here>
goto :eof
:: *** End subroutine "process"

:leave

The call :label is a way to simulate a subroutine call in a batch file (well, as nearly all the stuff described here, not for Win9x or plain DOS ...) The interpreter will jump to the label, pass any given arguments, continue until the end of the script ("goto :eof", which I reserve for the return of a "subroutine"), then return to the line after the "call :label".
Another useful trick is the ('type "%IniFile%"') in the "for /f" command, because you can handle paths with spaces in it that way. If you don't use quotation marks, the interpreter will try to look for the file until the space (and fail miserably), if you use quotation marks, the interpreter will handle the given path as a string, not as a file.

 

by: simonprrPosted on 2004-01-29 at 01:57:41ID: 10225712

In the process of testing this out. I'll let you know how I get on.

BTW, don't suppose you know of a command line zip util, like pkzip, that supposes long filenames do you? I've looked around, found one, but doesn't work!

 

by: simonprrPosted on 2004-01-29 at 07:04:02ID: 10226646

Ok I'm trying something else, but it's not working. I guess it needs another one of those for commands...

====makefile.bat=====
set title=
set name=
set date=
set time=
type blank.txt > test.txt
=================

====blank.txt========
Title is %title%
Name is %name%
Date is %date%
Time is %time%
=================

Basically I'm running makefile.bat and want it to create test.txt from blank.txt with the variable values. However all I get is a copy of blank.txt with the variable names not whats in the variables.

How can I do this successfully?

 

by: simonprrPosted on 2004-01-29 at 07:06:10ID: 10226662

Sorry missed some bits from makefile.bat... he's the right one:

====makefile.bat=====
set title=Test Run
set name=Si
set date=29.01.2004
set time=15:00
type blank.txt > test.txt
=================


Cheers
Quick response would be appreciated!

 

by: oBdAPosted on 2004-01-29 at 08:17:10ID: 10226989

Why the blank.txt instead of

Title is %Title% >test.txt
Name is %Name% >>test.txt
Date is %Date% >>test.txt
Time is %Time% >>test.txt

 

by: oBdAPosted on 2004-01-29 at 08:44:14ID: 10227129

Why the blank.txt instead of

Title is %Title% >test.txt
Name is %Name% >>test.txt
Date is %Date% >>test.txt
Time is %Time% >>test.txt

 

by: oBdAPosted on 2004-01-29 at 08:45:11ID: 10227138

Sorry for the double. The site seems to have intermittent problems at the moment.

 

by: simonprrPosted on 2004-01-29 at 09:03:55ID: 10227212

I seem to find that it does most of the time :(

Well, that is just a sample of blank.txt. It actually has a lot of other stuff all around that. By stuff I mean, ASCII art. It's just the way it has to look.
For example:

     ßßß  Ü²ÛÛÛÛ                                                ÛÛÛÛ²Ü  ßßß
    Üܲ²²ÛÛÛÛÛÛ                                                  ÛÛÛÛÛÛ²²²ÜÜ
   ²²ÛÛÛÛÛÛÛßß  Title.......[ %title%                       ßßÛÛÛÛÛÛÛ²²
  ²²ÛÛÛßß Ü     Name........[ %name%             Ü ßßÛÛÛ²²
 Ü²ÛÛÛ ÜÛ ²ÛÜ   Date........[ %date%                               ÜÛ² ÛÜ ÛÛÛ²Ü
 ²²ÛÛ  Ûß ²Û    YEAR.........[ 2004                                 Û² ßÛ  ÛÛ²²
 ²²ÛÛÛÜ ÜÛÛß                                                                 ßÛÛÜ ÜÛÛÛ²²
  ²²ÛÛÛÛÛÛß                                                                    ßÛÛÛÛÛÛ²²
   ß²²ÛÛÛÛ                                                            ÛÛÛÛ²²ß
         ²²²ÛÛÛÛÛÜÜ                                                  ÜÜÛÛÛÛÛ²²²
       ßßß ÛÛÛÛÛÛÛÜ ÛÛßÛ ÛÛßßßÛÛ   ÛÜ ÛßÛÛßÛßßÛÛßßÛÛßß ÛÛßß  ÜÛÛÛÛÛÛÛ ßßß
       Ü²²ÜÛÛ²²ßß²Û ²ÛÜß ²Ûß  ²Û   ²ÛÛÛ ²Û Û  ²Û  ²Ûß  ßßßÛ ²Û²ßß²²ÛÛܲ²Ü
      ²ÛÛÛÛÛ²²    Û ²Û ÛܲÛÛÛ ²ÛÛÛÜ²Û Û ²ÛÛÛ  ²Û  ²ÛÛÛܲÛÛÛ ²Û    ²²ÛÛÛÛÛ²
     ²Ûß  ß²²                                                      ²²ß  ßÛ²

That just gives you an idea, although may not look exactly right on here, due to formatting. So is there any way to do this?

 

by: simonprrPosted on 2004-01-29 at 09:05:47ID: 10227223

Ok well, that don't look that good in here, but in the type of viewer I use it looks cool.
I realise I could put ">>blank.txt echo" at the start of each line, but it's a long file, so I'm trying to get around having to put it on every line!

 

by: simonprrPosted on 2004-02-02 at 13:14:59ID: 10255865

Any ideas with that oBdA?

I've been playing with the checking of the FTP sites:

echo open 100.100.100.100 > uk2.ftp
echo USER bob >> uk2.ftp
echo pass >> uk2.ftp
echo quit >> uk2.ftp
ftp -n -s:uk2.ftp | find "Connected"
if errorlevel 0 goto upload
if errorlevel 1 goto checknextsite

However, this doesn't seem to work. It always goes to upload, whether it connects or not. I have tired with the >NUL bit aswell, but made no difference and with it on I can't see whats happening.

Have I done it wrong somewhere?

 

by: oBdAPosted on 2004-02-03 at 12:03:19ID: 10264502

As I said before: "if errorlevel x" means "if the errorlevel is x *or* *higher*".
Checking for errorlevel 0 doesn't make sense; that's *always* true. If you want to check for different errorlevels, you have to do so in revese order, the higher ones first.
Use the example I alread posted on 01/27/2004 12:14PM PST; put the routine for the next host where it says
:: *** another go at another host ...
Expand this for as many hosts as you need.

As for the ASCII graphics, that's theoretically doable, but it'll turn out an ugly mess. You'll need to get the string length as well to not distort the graphics, so it's probably easier to create this separately.

 

by: simonprrPosted on 2004-02-07 at 14:35:11ID: 10300435

Ok. Thanks. I've been playing about with a few things. Hopefully this question won't go on too much longer if all goes to plan :)

Decided to do the "Title is %Title% >test.txt" way, it simplier. But I've noticed that it doesn't like "&" symbols, probably cause they are used in the code, is there a way around this? I've noticed before in HTML code there are sometimes slashes before these characters, not sure if I need to do that.

Also, is there a way of echoing the last few lines of a log file to another file? Only specifying the last 10 lines for example?

The checking of the FTPs seems to be working now, but now the problem is that some of them are secure ones and I haven't found a command line FTP that support SSL/TLS. Without this is won't allow logon. Any ideas how to overcome this? Unless somehow I can find a way to capture the errorlevel from FlashFXP, when it can't connect for example?

Still got the problem of getting the length in time of the mp3 into a variable. Not sure how to overcome this. Can't find anything to do it!

Cheers!

 

by: oBdAPosted on 2004-02-08 at 07:46:34ID: 10303324

You can use the "&" symbol to put two commands into one line, like, for example, echo Line 1 & echo Line 2. This will not echo "Line 1 & echo Line 2", it will echo both lines. The escape character in a command shell is usually "^" (to output a "%", duplicate it).
echo Echoing an ampersand: ^&
echo Echoing a percent sign: %%

For the "x last lines" to work, you'll need to passes: One to get the number of lines in the original file, then output the desired number of lines.
The easiest way to do this is using "find" and "more", with some additional stuff for the caveats involved; here's an example:

@echo off
setlocal
:: *** The file of which the last lines to print:
set InFile=D:\Temp\test.cmd
:: *** The number of lines to show:
set LastLines=10

:: *** Check for a ":" in the file name; the ":" of the "find" output is used as delimiter, so the token number might have to be adjusted.
set Token=3
if "%InFile%"=="%InFile::=%" set Token=2
:: *** Get the numbr of lines in the file using "find"
for /f "tokens=%Token% delims=:" %%a in ('find /v /c "" "%InFile%"') do set TotalLines=%%a
echo Lines in %InFile%: %TotalLines%
:: *** Subtract the number of lines to be printed to get the number of lines to skip:
set /a SkipLines=TotalLines-LastLines
if %SkipLines% LSS 0 set SkipLines=0
echo Skipping %SkipLines% lines in the following output:
:: *** Use "more +n" to skip the unnecessary lines:
type "%InFile%" | more +%SkipLines%

As for the ftp problem, I'm afraid I don't have a recommendation either.
As for the mp3 length, the best solution is probably to post a specific request in the programmer's section. All the program needs to do is take an mp3 file name as argument and print the length of the file; seems doable (well, easy thing for me to say since I don't know anything about th mp3 format ...). You might add a 20 points pointer in the Applications/Multimedia section offering the the "programming" points for a an existing program that can do this.

 

by: simonprrPosted on 2004-02-08 at 10:11:31ID: 10304061

Great! Thanks. I'll try out that script in a bit.

Something else that I was playing with (that I thought would be easy) does seem to work...

I put the following in a batch file:

xcopy /t /e D:\ C:\Progra~1\Batch\Backup\D_Drive

Because I don't have enough room to backup the whole of my D: drive, so I thought I'd backup all the dirs. That way, it gives me an idea of whats on there and also a record base. However, whenever I run this it starts it, and does quite a lot of it, until suddenly comes up with "insufficent memory" and stops.

I've tried separating out the directories, into different commands, but same thing happens after a little while. Some of them do have a lot of folders in them, but still, seems a bit werid. Any way around this?

 

by: simonprrPosted on 2004-02-08 at 10:13:13ID: 10304072

I have 320MB RAM in my PC, I didn't think that would be a problem.

 

by: oBdAPosted on 2004-02-08 at 12:29:13ID: 10304603

Is that machine on the current SP level?
You May Not Be Able to Copy Large Files on Computers That Are Running Windows NT 4.0 or Windows 2000
http://support.microsoft.com/default.aspx?kbid=259837

Otherwise try to run it with the /L switch (which will list the files to be copied, but not actually copy them) and see where it stops.

 

by: simonprrPosted on 2004-02-08 at 15:10:16ID: 10305571

Yes, Windows 2000 Server SP4. I think that KB article is more about copying files in explorer. I'll try the /L switch.

 

by: simonprrPosted on 2004-02-08 at 15:26:08ID: 10305663

C:\>xcopy /t /e /l D:\ C:\Progra~1
Insufficient memory
79000 File(s)

Dunno why it says files, but there isn't that many directories.

 

by: simonprrPosted on 2004-02-10 at 08:18:38ID: 10323387

Resorted to using the tree and dir /b commands to give me lists. They seem to work fine. Pity really though.

Apart from that robvanderwoude.com site, which is really good, can you recommend any other batch file/command line utilities sites?

 

by: simonprrPosted on 2004-02-10 at 08:59:20ID: 10323801

> The checking of the FTPs seems to be working now, but now the problem is that some of them are secure ones and I haven't found a command > line FTP that support SSL/TLS. Without this is won't allow logon. Any ideas how to overcome this? Unless somehow I can find a way to capture > the errorlevel from FlashFXP, when it can't connect for example?

Also, thought I'd mention that I found a solution to the above, just in case your interested. I have found 2 utilities, TLSWrap and WinSSL. Both setup a type of FTP proxy server, on the local port (127.0.0.1) and a port you specify. You then connect to this hostname:port using FTP software and in the username field put: username@secureftphostname:port. This connects to the secure FTP site buffering the secure encryption of the FTP through themselves. Simple really, but very useful!

Now at least that's solved.

I have actually found some PAQs on here that seem to be similar to what I need for the mp3 length. However, because they are PAQ I need to be a premium user to read the answers! I wish they offered a $1/answer solution or something. Don't suppose you are a premium user are you?

 

by: simonprrPosted on 2004-02-11 at 03:37:01ID: 10331252

Ok I got an another small query for you....

Can you use dos to parse text files?

Let me explain...I download a webpage tracklisting every week, but of course this webpage contains a lot of other information that I don't need. Is there a way to setup a script so that it looks at the downloaded web page and analyises it. Looks for a certain phrase such as "Tracklisting 11/02/04" and copies all the text from that point. Sometimes, the tracklisting isn't updated and therefore the previous weeks tracklist is on the site, so I need it to identify the date and only copy the text if the date matches the current date (which I do have in variables %day% %month% %year%). I really then need to get each line of this tracklisting into a variable so that I can add it to my section with the ASCII art and where it echoing other information into a text file.

I realise this is quite a lot, but of what I've seen it should be possible, shouldn't it?

Thanks alot :)

 

by: simonprrPosted on 2004-02-13 at 18:46:12ID: 10358543

Someone in my programming question for the mp3 length has responded!

http://www.experts-exchange.com/Programming/Q_20879867.html#10352707

I've tested it using one of my sample mp3s:

===========================
No edits specified; only reading input data

Creating index file D:/Test.idx

Elapsed time:    0:01|     1.018s|Frame: 39    

Elapsed time:    0:02|     2.011s|Frame: 77    

Elapsed time:    0:03|     3.004s|Frame: 115    

Elapsed time:    0:04|     4.022s|Frame: 154    

Elapsed time:    0:05|     5.015s|Frame: 192    

Elapsed time:    0:06|     6.008s|Frame: 230    

Elapsed time:    0:07|     7.000s|Frame: 268    

Elapsed time:    0:08|     8.019s|Frame: 307    

Elapsed time:    0:09|     9.012s|Frame: 345    

Elapsed time:    0:10|    10.004s|Frame: 383    

Elapsed time:    0:11|    11.023s|Frame: 422    

Elapsed time:    0:12|    12.016s|Frame: 460    

Elapsed time:    0:13|    13.008s|Frame: 498    

Elapsed time:    0:14|    14.001s|Frame: 536    

Elapsed time:    0:15|    15.020s|Frame: 575    

Elapsed time:    0:16|    16.012s|Frame: 613    

Elapsed time:    0:17|    17.005s|Frame: 651    

Elapsed time:    0:18|    18.024s|Frame: 690    

Elapsed time:    0:19|    19.016s|Frame: 728    

Elapsed time:    0:20|    20.009s|Frame: 766    

Elapsed time:    0:21|    21.002s|Frame: 804    

Elapsed time:    0:22|    22.020s|Frame: 843    

Elapsed time:    0:23|    23.013s|Frame: 881    

Elapsed time:    0:24|    24.006s|Frame: 919    

Elapsed time:    0:25|    25.024s|Frame: 958    

Elapsed time:    0:26|    26.017s|Frame: 996    

Elapsed time:    0:27|    27.010s|Frame: 1034  

Elapsed time:    0:28|    28.002s|Frame: 1072  

Elapsed time:    0:29|    29.021s|Frame: 1111  

Elapsed time:    0:30|    30.014s|Frame: 1149  

Elapsed time:    0:31|    31.006s|Frame: 1187  

Elapsed time:    0:32|    32.025s|Frame: 1226  

Elapsed time:    0:33|    33.018s|Frame: 1264  

Elapsed time:    0:34|    34.010s|Frame: 1302  

Elapsed time:    0:35|    35.003s|Frame: 1340  

Elapsed time:    0:36|    36.022s|Frame: 1379  

Elapsed time:    0:37|    37.014s|Frame: 1417  

Elapsed time:    0:38|    38.007s|Frame: 1455  

Elapsed time:    0:39|    39.000s|Frame: 1493  

Elapsed time:    0:40|    40.018s|Frame: 1532  

Elapsed time:    0:41|    41.011s|Frame: 1570  

Elapsed time:    0:42|    42.004s|Frame: 1608  

Elapsed time:    0:43|    43.022s|Frame: 1647  

Elapsed time:    0:44|    44.015s|Frame: 1685  

Elapsed time:    0:45|    45.008s|Frame: 1723  

Elapsed time:    0:46|    46.000s|Frame: 1761  

Elapsed time:    0:47|    47.019s|Frame: 1800  

Elapsed time:    0:48|    48.012s|Frame: 1838  

Elapsed time:    0:49|    49.004s|Frame: 1876  

Elapsed time:    0:50|    50.023s|Frame: 1915  

Elapsed time:    0:51|    51.016s|Frame: 1953  

Elapsed time:    0:52|    52.008s|Frame: 1991  

Elapsed time:    0:53|    53.001s|Frame: 2029  

Elapsed time:    0:54|    54.020s|Frame: 2068  

Elapsed time:    0:55|    55.012s|Frame: 2106  

Elapsed time:    0:56|    56.005s|Frame: 2144  

Elapsed time:    0:57|    57.024s|Frame: 2183  

Elapsed time:    0:58|    58.016s|Frame: 2221  

Elapsed time:    0:59|    59.009s|Frame: 2259  

Elapsed time:    1:00|    60.002s|Frame: 2297  

Elapsed time:    1:01|    61.020s|Frame: 2336  

Elapsed time:    1:02|    62.013s|Frame: 2374  

Elapsed time:    1:03|    63.006s|Frame: 2412  

Elapsed time:    1:04|    64.025s|Frame: 2451  

Elapsed time:    1:05|    65.017s|Frame: 2489  

Elapsed time:    1:06|    66.010s|Frame: 2527  

Elapsed time:    1:07|    67.002s|Frame: 2565  

Elapsed time:    1:08|    68.021s|Frame: 2604  

Elapsed time:    1:09|    69.014s|Frame: 2642  

Elapsed time:    1:10|    70.006s|Frame: 2680  

Elapsed time:    1:11|    71.025s|Frame: 2719  

Elapsed time:    1:12|    72.018s|Frame: 2757  

Elapsed time:    1:13|    73.010s|Frame: 2795  

Elapsed time:    1:14|    74.003s|Frame: 2833  

Elapsed time:    1:15|    75.022s|Frame: 2872  

Elapsed time:    1:16|    76.015s|Frame: 2910  

Elapsed time:    1:17|    77.007s|Frame: 2948  

Elapsed time:    1:18|    78.000s|Frame: 2986  

Elapsed time:    1:19|    79.019s|Frame: 3025  

Elapsed time:    1:20|    80.011s|Frame: 3063  

Elapsed time:    1:21|    81.004s|Frame: 3101  

Elapsed time:    1:22|    82.023s|Frame: 3140  

Elapsed time:    1:23|    83.015s|Frame: 3178  

Elapsed time:    1:24|    84.008s|Frame: 3216  

Elapsed time:    1:25|    85.000s|Frame: 3254  

Elapsed time:    1:26|    86.019s|Frame: 3293  

Elapsed time:    1:27|    87.012s|Frame: 3331  

Elapsed time:    1:28|    88.005s|Frame: 3369  

Elapsed time:    1:29|    89.023s|Frame: 3408  

Elapsed time:    1:30|    90.016s|Frame: 3446  

Elapsed time:    1:31|    91.009s|Frame: 3484  

Elapsed time:    1:32|    92.001s|Frame: 3522  

Elapsed time:    1:33|    93.020s|Frame: 3561  

Elapsed time:    1:34|    94.013s|Frame: 3599  

Elapsed time:    1:35|    95.005s|Frame: 3637  

Elapsed time:    1:36|    96.024s|Frame: 3676  

Elapsed time:    1:37|    97.017s|Frame: 3714  

Elapsed time:    1:38|    98.009s|Frame: 3752  

Elapsed time:    1:39|    99.002s|Frame: 3790  

Elapsed time:    1:40|   100.021s|Frame: 3829  

Elapsed time:    1:41|   101.013s|Frame: 3867  

Elapsed time:    1:42|   102.006s|Frame: 3905  

Elapsed time:    1:43|   103.025s|Frame: 3944  

Elapsed time:    1:44|   104.017s|Frame: 3982  

Elapsed time:    1:45|   105.010s|Frame: 4020  

Elapsed time:    1:46|   106.003s|Frame: 4058  

Elapsed time:    1:47|   107.021s|Frame: 4097  

Elapsed time:    1:48|   108.014s|Frame: 4135  

Elapsed time:    1:49|   109.007s|Frame: 4173  

Elapsed time:    1:50|   110.025s|Frame: 4212  

Elapsed time:    1:51|   111.018s|Frame: 4250  

Elapsed time:    1:52|   112.011s|Frame: 4288  

Elapsed time:    1:53|   113.003s|Frame: 4326  

Elapsed time:    1:54|   114.022s|Frame: 4365  

Elapsed time:    1:55|   115.015s|Frame: 4403  

Elapsed time:    1:56|   116.007s|Frame: 4441  

Elapsed time:    1:57|   117.000s|Frame: 4479  

Elapsed time:    1:58|   118.019s|Frame: 4518  

Elapsed time:    1:59|   119.011s|Frame: 4556  

Elapsed time:    2:00|   120.004s|Frame: 4594  

Elapsed time:    2:01|   121.023s|Frame: 4633  

Elapsed time:    2:02|   122.015s|Frame: 4671  

Elapsed time:    2:03|   123.008s|Frame: 4709  

Elapsed time:    2:04|   124.001s|Frame: 4747  

Elapsed time:    2:05|   125.019s|Frame: 4786  

Elapsed time:    2:06|   126.012s|Frame: 4824  

Elapsed time:    2:07|   127.005s|Frame: 4862  

Elapsed time:    2:08|   128.023s|Frame: 4901  

Elapsed time:    2:09|   129.016s|Frame: 4939  

Elapsed time:    2:10|   130.009s|Frame: 4977  

done.


File name:    D:\Test.mp3
CBR:          192
Total frames: 5014
File size:    3143471
Track length: 2:10.975 (130s)
==============================

And thats with a 2minute long mp3!! A lot of stuff that needs to be cut out, or ignored! So basically all we need to go is capture the bit of "Track length: 2:10.975 (130s)" the "2:10" bit only.

Hope this be possible!

I would increase the points further, but there isn't the option for it. I will post another question after this one to give you more points for all your help as I keep asking more and more things.

Thanks again :)

 

by: oBdAPosted on 2004-02-14 at 09:00:09ID: 10361502

Okay, retrieving the track length is rather easy now:

for /f "tokens=3 delims=. " %%a in ('S:\ome\Path\mpgedit.exe %YourMP3File% ^| find /i "Track length"') do set Length=%%a
echo Length: [%Length%]

Note that there is a space between 'delims=.' and the closing quotation mark, and you need of course to adjust the "mpgedit" command.

As for downloading and parsing the website, that should be doable, but that should be put into a different question; it's not about the points for me, but it's not connected to the initial question any more and it makes it harder for people looking for similar problems to find what they're looking for. Not to mention that others should have a chance to participate in your questions as well ;)
If you decide to ask another question, feel free to post a link to it here.

 

by: simonprrPosted on 2004-02-14 at 10:15:19ID: 10361968

Great, that worked brilliantly! :)

Ok fair enough, I'll post another question for the file parsing. Shall I post it in this section or the programming section? I do really need it done in dos again, so here would be best.

Well all thats left to do is the parsing and part 2 of that other programming question.

Thanks for all your help, it's been extremely helpful!

Cheers :D

 

by: oBdAPosted on 2004-02-14 at 12:25:49ID: 10362449

You're welcome.
If you need this in a windows shell script, the DOS section is probably your best bet (even though, technically speaking, this isn't DOS at all).

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...