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
Jun 17 2009, 09:19 AM Post
#1 | |
| Group: Members Posts: 3 Joined: 3-June 09 Member No.: 246342 OS: XP Pro x64 | 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. |
| | |
![]() |
Jun 17 2009, 09:32 AM Post
#2 | |
| MSFN SuperB Group: Software Developers Posts: 5048 Joined: 23-July 04 From: Italy Member No.: 25215 OS: none | 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 |
| | |
Jun 17 2009, 09:37 AM Post
#3 | |
| Free cookies ![]() ![]() ![]() Group: Members Posts: 336 Joined: 8-November 07 Member No.: 161647 OS: XP Pro x86 | |
| | |
Jun 17 2009, 09:50 AM Post
#4 | |
| MSFN SuperB Group: Software Developers Posts: 5048 Joined: 23-July 04 From: Italy Member No.: 25215 OS: none |
@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 |
| | |
Jun 17 2009, 12:11 PM Post
#5 | |
| Free cookies ![]() ![]() ![]() Group: Members Posts: 336 Joined: 8-November 07 Member No.: 161647 OS: XP Pro x86 |
True that jaclaz. |
| | |
Jun 17 2009, 03:39 PM Post
#6 | |
| Coffee Aficionado Group: Super Moderator Posts: 3716 Joined: 14-July 04 From: Coffeeland Member No.: 24596 OS: Windows 7 x64 | 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 |
| | |
Jun 17 2009, 03:45 PM Post
#7 | |
| Free cookies ![]() ![]() ![]() Group: Members Posts: 336 Joined: 8-November 07 Member No.: 161647 OS: XP Pro x86 | 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. |
| | |
Jun 17 2009, 04:14 PM Post
#8 | |
| Coffee Aficionado Group: Super Moderator Posts: 3716 Joined: 14-July 04 From: Coffeeland Member No.: 24596 OS: Windows 7 x64 | 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) |
| | |
Jun 17 2009, 11:28 PM Post
#9 | |
| Group: Members Posts: 3 Joined: 3-June 09 Member No.: 246342 OS: XP Pro x64 |
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 . |
| | |
Jun 18 2009, 04:03 AM Post
#10 | |
| MSFN SuperB Group: Software Developers Posts: 5048 Joined: 23-July 04 From: Italy Member No.: 25215 OS: none |
Let's do baby steps then. Open a command prompt. Type in it CODE DIR C:\*.avi /B /S and press ENTER This will make a list of all .avi files in C:\ Now type: CODE 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: CODE 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: CODE @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 |
| | |
Jun 20 2009, 04:29 AM Post
#11 | |
| Group: Members Posts: 3 Joined: 3-June 09 Member No.: 246342 OS: XP Pro x64 |
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. |
| | |
![]() ![]() |
| Lo-Fi Version | Time is now: 24th November 2009 - 04:26 PM |