search a file(s) name having specific string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
wasimsono
Posts: 11
Joined: 03 Apr 2017 06:06

search a file(s) name having specific string

#1 Post by wasimsono » 12 Jul 2017 02:07

Dear All

I have a number of files. Name of these files consist "Area name" and "Book No" like 123401: in this 1234 is the name of area and 01 is Book No. I want to design a batch file which gets a string (Area Name) form user and find that book from a specific folder.

Urgent help is required.

Thanks a lot in advance.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: search a file(s) name having specific string

#2 Post by penpen » 12 Jul 2017 09:07

I'm unsure qhat you are looking for:
What do you mean with "find that book from a specific folder"?

Unless you haven't forgotten to mention something, once you have the "Area name" and "Book No" you won't need to search for the file in your "specific folder" (in EBNF notation):
"<specific_folder>\<Area name><Book No>".

Maybe i'm wrong, but this task sounds like a homework for school, or something similar:
You might use "set /P" to read user input into a variable;
type "help set" into the command shell ("cmd.exe") for further information.

What do you have so far, and which is the part you need help with?


penpen

wasimsono
Posts: 11
Joined: 03 Apr 2017 06:06

Re: search a file(s) name having specific string

#3 Post by wasimsono » 13 Jul 2017 04:54

Thanks penpen for taking interest.

Actually we have a lot of files every month on a ftp server. These files have data about meter reading of customers. Programmers had designed tables without "Area" & "Book" fields. So these files contain data without area name and book no. I have to design an inquiry program which collects data from these files. Now If user want to display the data of a particular file: means for book 01 of area 1234: I have to search that file in the collection or folder and then process the data of that file.
I hope now you can understand the situation.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: search a file(s) name having specific string

#4 Post by penpen » 13 Jul 2017 09:58

If i've understand right, then you have stored all files in a database directory (lets assume it is "D:\"),
so your directory structure containing all "books" is something like that:

Code: Select all

D:\
+---123401
+---123402
 ...
+---567801

If you are searching for Book No 02 in Area 1234, then your file's location is "D:\123402".

A batch file ("book.bat") echoing the full path to the book (without any validity check) then is:

Code: Select all

@echo("D:\%~1%~2"

You may use the above batch, by calling "book.bat", setting the first parameter to the needed AreaName and the second parameter to the needed Book no:

Code: Select all

@echo off
call book.bat "1234" "01"

So i still think i miss something.


penpen

Dsel
Posts: 1
Joined: 31 Jul 2017 16:33

Re: search a file(s) name having specific string

#5 Post by Dsel » 31 Jul 2017 16:37

wasimsono wrote:Thanks penpen for taking interest.

Actually we have a lot of files every month on a ftp server. These files have data about meter reading of customers. Programmers had designed tables without "Area" & "Book" fields. So these files contain data without area name and book no. I have to design an inquiry program which collects data from these files. Now If user want to display the data of a particular file: means for book 01 of area 1234: I have to search that file in the collection or folder and then process the data of that file.
I hope now you can understand the situation.



@echo off

rem SM_MAXCADASTRO_17_01_005.ZIP

set servidor=%USERPROFILE%\Desktop\batch\arquivos
set modulo=SM_MAXCADASTRO
set versao1=17
set versao2=01
set versao3=000
set extensao=zip
set existe=

call:verifica %servidor%, %modulo%, %versao1%, %versao2%, %versao3%, %extensao%
echo %existe%
echo.&pause&goto:eof

:verifica

if exist %~1\%~2_%~3_%~4_%~5.%~6 (
set existe=1
) else (
set existe=0
)

goto:eof

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: search a file(s) name having specific string

#6 Post by Hackoo » 01 Aug 2017 03:14

@OP
Did you mean search a file having specfic string in the name or in their contents :?:
It's unclear until now for me :?:

Post Reply