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
read file names and call bat files [SOLVED]
Moderator: DosItHelp
-
- Posts: 2
- Joined: 16 Apr 2012 13:17
read file names and call bat files [SOLVED]
Last edited by dostips2012 on 18 Apr 2012 06:05, edited 1 time in total.
Re: newbie needs help - read file names and call bat files
I don't know if I understood it correctly, but here it goes.
Untested:
About the "move" part, you have to say what exactly you want to move to Folder1\Archive.
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.
Re: newbie needs help - read file names and call bat files
And if you are using Windows Vista or 7 you could substitute the PING commands with the TIMEOUT command.
Re: newbie needs help - read file names and call bat files
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.
Re: newbie needs help - read file names and call bat files
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
)
)
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
)
)
-
- Posts: 2
- Joined: 16 Apr 2012 13:17
Re: read file names and call bat files [SOLVED]
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!
Thank you all for quick response. You guys are awesome!