nicolas Posted June 17, 2009 Share Posted June 17, 2009 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. Link to comment Share on other sites More sharing options...
jaclaz Posted June 17, 2009 Share Posted June 17, 2009 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/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 Link to comment Share on other sites More sharing options...
beats Posted June 17, 2009 Share Posted June 17, 2009 Google is your friend. Link to comment Share on other sites More sharing options...
jaclaz Posted June 17, 2009 Share Posted June 17, 2009 @beatsYEP. But try timing how much it takes using dir in a batch FOR loop and compare it with the mentioned command line app. jaclaz Link to comment Share on other sites More sharing options...
beats Posted June 17, 2009 Share Posted June 17, 2009 True that jaclaz. Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 17, 2009 Share Posted June 17, 2009 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 Link to comment Share on other sites More sharing options...
beats Posted June 17, 2009 Share Posted June 17, 2009 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 extensionFrom 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. Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 17, 2009 Share Posted June 17, 2009 does exactly what he wantsI 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) Link to comment Share on other sites More sharing options...
nicolas Posted June 18, 2009 Author Share Posted June 18, 2009 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 . Link to comment Share on other sites More sharing options...
jaclaz Posted June 18, 2009 Share Posted June 18, 2009 Let's do baby steps then.Open a command prompt.Type in itDIR C:\*.avi /B /Sand press ENTERThis 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 ENTERThis 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 ENTERThis 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 fileSETLOCAL ENABLEEXTENSIONSSETLOCAL ENABLEDELAYEDEXPANSIONSET wanted=IF %1.==. (SET /P wanted=Please input a filename, and press ENTER: ) ELSE (SET wanted=%*)CALL :splitinput "%wanted%"IF NOT DEFINED wantedname GOTO :EOFFOR /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:splitinputIF %1.=="". GOTO :EOFSET wantedname="%~n1"SET wantedext=%~x1IF NOT DEFINED wantedext SET /P wantedext=Input extension and press ENTER or just press ENTER for [.avi]IF NOT DEFINED wantedext SET wantedext=.aviIF NOT %wantedext:~0,1%.==.. SET wantedext=.%wantedext%GOTO :EOFPlease 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 Link to comment Share on other sites More sharing options...
nicolas Posted June 20, 2009 Author Share Posted June 20, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now