read file names and call bat files [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dostips2012
Posts: 2
Joined: 16 Apr 2012 13:17

read file names and call bat files [SOLVED]

#1 Post by dostips2012 » 16 Apr 2012 13:21

I need help in coding for below logic. I've some interaction with dos coding:

Do till all files processed in "Folder1"
If prefix of file name = prefix1, then goto prefix1_tag
If prefix of file name = prefix2, then goto prefix2_tag
If prefix of file name = prefix3, then goto prefix3_tag
Enddo

tag prefix1_tag:
call prefix1_tag_sftp.bat
Move to Folder1\Archive
wait for 5 min

tag prefix2_tag:
call prefix2_tag_sftp.bat
Move to Folder1\Archive
wait for 5 min

tag prefix3_tag:
call prefix3_tag_sftp.bat
Move to Folder1\Archive
wait for 5 min
Last edited by dostips2012 on 18 Apr 2012 06:05, edited 1 time in total.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: newbie needs help - read file names and call bat files

#2 Post by Fawers » 16 Apr 2012 16:01

I don't know if I understood it correctly, but here it goes.
Untested:
@echo off
set "prefix=prefix1 prefix2 prefix3"
::set "prefix" to all your file prefixes; each one must be separated by a blank space
::i'll use prefix1, prefix2 and prefix3 as an example
for %%a in (%prefix%) do call :%%a_tag "%%a"
goto eof

:prefix1_tag
call "%~1_tag_sftp.bat"
::move (see out of code box)
>nul ping -n 301 localhost
exit /b

:prefix2_tag
call "%~1_tag_sftp.bat"
::move (see out of code box)
>nul ping -n 301 localhost
exit /b

:prefix3_tag
call "%~1_tag_sftp.bat"
::move (see out of code box)
>nul ping -n 301 localhost
exit /b

:eof

About the "move" part, you have to say what exactly you want to move to Folder1\Archive.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: newbie needs help - read file names and call bat files

#3 Post by Squashman » 16 Apr 2012 16:12

And if you are using Windows Vista or 7 you could substitute the PING commands with the TIMEOUT command.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: newbie needs help - read file names and call bat files

#4 Post by Fawers » 16 Apr 2012 16:23

Squashman wrote:And if you are using Windows Vista or 7 you could substitute the PING commands with the TIMEOUT command.

Didn't know of that one. Will try it on my 7.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: newbie needs help - read file names and call bat files

#5 Post by foxidrive » 16 Apr 2012 16:56

How do you define the prefix in a filename? Is it the first word of a filename separated by a space or underscore?

If so then this could work (untested):

@echo off
for %%a in (*.*) do (
for /f "delims=_ " %%b in ("%%a") do (
call "%%b_tag_sftp.bat"
Move "%%a" "Folder1\Archive"
ping -n 301 localhost >nul
)
)

dostips2012
Posts: 2
Joined: 16 Apr 2012 13:17

Re: read file names and call bat files [SOLVED]

#6 Post by dostips2012 » 18 Apr 2012 06:09

I took foxidrive's idea since my filename has underscore. This way the code is simple and we don't have to update it if a new prefix is found, we just add a new _tag_sftp.bat file.

Thank you all for quick response. You guys are awesome!

Post Reply