MSFN Forum: Batch File - MSFN Forum

Jump to content



Unattended CD/DVD Guide Homepage · MSFN Forum Rules

Welcome to the Applications Installs forum. Make sure you read the forum rules before you start posting.

Links/Requests to warez and/or any illegal material (porn, cracks, serials, etc..) will not be tolerated. Discussion of circumventing WGA/activation/timebombs/keygens or any other illegal activity will also not be tolerated.

We try our best to keep this forum clean of illegal content. If you see any illegal activity use the "report" button you find in every post to report the specific post to the moderators. If you ignore any of the rules you will be banned without notice.

Read Forum Rules
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch File Batch searching for any .avi file in folder Rate Topic: -----

#1 User is offline   nicolas 

  • Group: Members
  • Posts: 3
  • Joined: 03-June 09

Posted 17 June 2009 - 09:19 AM

:wacko:
Hi everyone,

I am trying for at least this past week to create my own batch file which would seek in any directories and folders for any filename with .avi extension.

second problem which i couldn't figure it out is let's say when my file (Newfile.avi) located in folder E:\movies, and i would like it to search any name with the correct extension put it into a variable so that i could play it later with a cmd.exe command.

I do not know if what i request is possible to do as i managed to put any text input from my notepad, but i couldn't tell it to initialise any .avi file name found straight from E:\movies.

I have read countless sites to get similar code with i could adapt to my own taste but nothing found which i could translate to ok english. I have tried so many variosu method of if and for statement but i really get confuse with the for statement even after many articles or from the help command line.

Please help, thanks for any support

I feel like the more I read about batch and the more I really feel I do not know much about Batch file.


#2 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 9,086
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 17 June 2009 - 09:32 AM

View Postnicolas, on Jun 17 2009, 05:19 PM, said:

I am trying for at least this past week to create my own batch file which would seek in any directories and folders for any filename with .avi extension.

Any reason for not wanting to use a command line application?

Are ALL the drives/partitions formatted as NTFS?

If yes, looky here:
http://ndff.hotbox.ru/en/

View Postnicolas, on Jun 17 2009, 05:19 PM, said:

second problem which i couldn't figure it out is let's say when my file (Newfile.avi) located in folder E:\movies, and i would like it to search any name with the correct extension put it into a variable so that i could play it later with a cmd.exe command.

I am not sure to have understood what you mean, can you post a more detailed description of WHAT you would like to do (as oppposed ot HOW you think it should be done) ?

jaclaz

#3 User is offline   beats 

  • Free cookies
  • PipPipPip
  • Group: Members
  • Posts: 344
  • Joined: 08-November 07

Posted 17 June 2009 - 09:37 AM

Google is your friend. :)

#4 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 9,086
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 17 June 2009 - 09:50 AM

@beats

YEP. :)

But try timing how much it takes using dir in a batch FOR loop and compare it with the mentioned command line app. ;)

jaclaz

#5 User is offline   beats 

  • Free cookies
  • PipPipPip
  • Group: Members
  • Posts: 344
  • Joined: 08-November 07

Posted 17 June 2009 - 12:11 PM

True that jaclaz. ;)

#6 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,257
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 17 June 2009 - 03:39 PM

View Postjaclaz, on Jun 17 2009, 11:32 AM, said:

I am not sure to have understood what you mean, can you post a more detailed description of WHAT you would like to do (as oppposed ot HOW you think it should be done) ?

I read it 3 times slow, and I have NO idea what he's trying to do, other than it has to search for files, with a certain extension

#7 User is offline   beats 

  • Free cookies
  • PipPipPip
  • Group: Members
  • Posts: 344
  • Joined: 08-November 07

Posted 17 June 2009 - 03:45 PM

View PostCoffeeFiend, on Jun 17 2009, 11:39 PM, said:

I read it 3 times slow, and I have NO idea what he's trying to do, other than it has to search for files, with a certain extension

From what I understood, he insists on using a batch file instead of a tool, and the batch file I linked to, does exactly what he wants. In fact, it does even more, since that particular batch file accepts ANY file name as an argument. ;)

#8 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,257
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 17 June 2009 - 04:14 PM

View Postbeats, on Jun 17 2009, 05:45 PM, said:

does exactly what he wants

I didn't look, but just by the link's name, it seems like a batch file to delete stuff. And I have no idea where you got that "delete" part from in his post, that's where I'm getting at. I have absolutely NO idea what it's supposed to do (not that I'd really use a batch file for that kind of stuff in the first place anyways)

#9 User is offline   nicolas 

  • Group: Members
  • Posts: 3
  • Joined: 03-June 09

Posted 17 June 2009 - 11:28 PM

Thanks you all for any answers provided. My request was a bit confusing to understand so i am going to break it into smaller part.

First , i need a batch file which will loop into each drives and folders (C:\Movies) and seek any files names which has the avi extension (Mymoviefile.avi) for example.

then this is where I really get stuck, I need a variable to stock either the filename (Mymoviefile) or the name of the folder in which the avi file is located. Ex:my variable NameMov="".

Then i would need that variable to input the filename (mymoviefile) into the variable.

This is so that i could after make a comparaison test against a user's keyboard input and if it is the same name then it should go and play it, if it is not the same file then it must carry on looping to the next filename of any .avi file found until it found a match or until a echo stating: "no movie file found " for instance.

Voila I do hope this was much explicit for everyone to understand my request.

All possible ideas or explainations will be a great help

Thanks to all .

#10 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 9,086
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 18 June 2009 - 04:03 AM

Let's do baby steps then.

Open a command prompt.

Type in it
DIR C:\*.avi /B /S

and press ENTER
This will make a list of all .avi files in C:\

Now type:
FOR /F %? IN ('DIR C:\*.avi /B /S') DO SET Filename=%?

and press ENTER
This will make a list of all .avi files in C:\ and for each item in the list will set the variable Filename to the actual found filename.

Now, assuming you have a .avi file named myfile type:
FOR /F %? IN ('DIR C:\*myfile.avi /B /S') DO SET Filename=%?

and press ENTER
This will make a list of all files named myfile.avi files in C:\ and for each item in the list will set the variable Filename to the actual found filename.

You just add some error control and an input interface and you are done:

@ECHO OFF
::FINDFILE.CMD small batch file by jaclaz to find a given file
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

SET wanted=
IF %1.==. (
SET /P wanted=Please input a filename, and press ENTER: 
) ELSE (
SET wanted=%*
)
CALL :splitinput "%wanted%"

IF NOT DEFINED wantedname GOTO :EOF
FOR /F %%? IN ('DIR C:\*%wantedname%%wantedext% /B /S') DO (
SET fullfilename="%%?"
ECHO File %wantedname% was found with extension %wantedext% in:
ECHO !fullfilename!
PAUSE &GOTO :EOF
)
ECHO File NOT found!&PAUSE 
GOTO :EOF


:splitinput
IF %1.=="". GOTO :EOF
SET wantedname="%~n1"
SET wantedext=%~x1
IF NOT DEFINED wantedext SET /P wantedext=Input extension and press ENTER or just press ENTER for [.avi]
IF NOT DEFINED wantedext SET wantedext=.avi
IF NOT %wantedext:~0,1%.==.. SET wantedext=.%wantedext%
GOTO :EOF


Please note that in case of several copies of the same file "myfile.avi" OR with a number of filenames like:
"this_is_myfile.avi"
"23myfile.avi"
"anothermyfile.avi"
etc.

The batch will output ONLY first matching occurrence (to avoid continue scanning drive once occurrence is found).

jaclaz

#11 User is offline   nicolas 

  • Group: Members
  • Posts: 3
  • Joined: 03-June 09

Posted 20 June 2009 - 04:29 AM

Thank you so much jaclaz.

I just checked your reply and I will try it right away. Yes indeed baby step was exactly what i needed.

I managed to understand that i would need to setlocal enabledelayedexpansion and it did what i wanted but i couldn't make a loop which will read myfile.text line by line and input the result into a variable which i could have tested later on.

Through this little exercice i learn more than expected.

i will reply again to let you know how it goes.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy