Batch to get file name
Moderator: DosItHelp
Batch to get file name
Hi everyone.
Firstable I'll like to say sorry by my awful English.
Involved elements:
External USB hard disk
Windows 2003 Server R2 standar edition
Windows XP Professional SP3
Filezilla Server 0.9.33 beta
Blat 2.6.2
Directory monitor 1.0.1.23
What I do:
I have external hard disk connected to W2003 a shared. From XP I have a mapped this hard disk using UNC and this unit is for store files that people upload to FTP server.
I need make a bat that when new file start upload make these actions:
1.-Get file name
2.-Get folder name
3.-Send a email with this data (file and folder name) using Blat
4.-When upload finished send email using Blat to inform that this file is ready to start download
I've done so far:
Using Directory monitor detect that a new file is start upload and call a bat that send me an email using Blat with Folder name in a subject.
This code works:
@echo off
cd folderexample
for %%* in (.) do set var=%%~n*
for /f %%a in ('time/t') do set vartime=%%a
set body=-body "Test|Hello World"
set from=i@example.com
set to=example@example.com
set subj=-s "Test. FTP.%var%. New Files. %vartime%"
set server=-server smtp.example.com
set user=-u userexample
set pass= -pw passwordexample
C:\Bats\Blat\full\blat %0 -f %from% -b %to% %subj% %body% %server% %user% %pass%
Thanks in advance.
Firstable I'll like to say sorry by my awful English.
Involved elements:
External USB hard disk
Windows 2003 Server R2 standar edition
Windows XP Professional SP3
Filezilla Server 0.9.33 beta
Blat 2.6.2
Directory monitor 1.0.1.23
What I do:
I have external hard disk connected to W2003 a shared. From XP I have a mapped this hard disk using UNC and this unit is for store files that people upload to FTP server.
I need make a bat that when new file start upload make these actions:
1.-Get file name
2.-Get folder name
3.-Send a email with this data (file and folder name) using Blat
4.-When upload finished send email using Blat to inform that this file is ready to start download
I've done so far:
Using Directory monitor detect that a new file is start upload and call a bat that send me an email using Blat with Folder name in a subject.
This code works:
@echo off
cd folderexample
for %%* in (.) do set var=%%~n*
for /f %%a in ('time/t') do set vartime=%%a
set body=-body "Test|Hello World"
set from=i@example.com
set to=example@example.com
set subj=-s "Test. FTP.%var%. New Files. %vartime%"
set server=-server smtp.example.com
set user=-u userexample
set pass= -pw passwordexample
C:\Bats\Blat\full\blat %0 -f %from% -b %to% %subj% %body% %server% %user% %pass%
Thanks in advance.
Re: Batch to get file name
I have no idea about this stuff. You wrote "Directory Monitor" is watching the folder for new files. OK I don't know this software. What is the interface that you could use between your batch process and the Directory Monitor process?
Regards
aGerman
Regards
aGerman
Re: Batch to get file name
Thanks for your reply aGerman.
No i didn't wrote "Directory Monitor". I just a normal user. I found this software in the web. This software has a option that when new file arrive to monitored folder you can launch a program in this case a ".bat".
No i didn't wrote "Directory Monitor". I just a normal user. I found this software in the web. This software has a option that when new file arrive to monitored folder you can launch a program in this case a ".bat".
Re: Batch to get file name
I'm sure batch is not the best for such things, but you could play with that.
First you should connect a volume (Z: for my example) with the server share where the files should be searched.
In subroutine :message you can do your blat stuff.
Regards
aGerman
First you should connect a volume (Z: for my example) with the server share where the files should be searched.
Code: Select all
@echo off &setlocal enabledelayedexpansion
for /f "tokens=1* delims=:" %%a in ('dir /a-d /b Z:\^|findstr /n .') do set /a n=%%a &set "old%%a=%%b"
:loop
for /f "delims=" %%a in ('dir /a-d /b Z:\') do (
set "newName=%%a"
call :procFileName
)
goto :loop
:procFileName
set "found=0"
for /l %%a in (1,1,%n%) do (
set "oldName=!old%%a!"
if "!oldName!"=="!newName!" set "found=1"
)
if %found%==1 goto:eof
set /a n+=1
set "old!n!=!newName!"
call :message
goto :eof
:message
:: *** your blat stuff here, file name is in !newName!
echo !newName!
goto :eof
In subroutine :message you can do your blat stuff.
Regards
aGerman
Re: Batch to get file name
Ufff!!!
Just incredible!!
I see the code and i can't understand nothing but i try now and tell.
Thanks for your help aGerman.
The world make sense with people like you.
Thanks.
Just incredible!!
I see the code and i can't understand nothing but i try now and tell.
Thanks for your help aGerman.
The world make sense with people like you.
Thanks.
Re: Batch to get file name
I try you code and open a new command window black and nothing happens.
I think that the code come in to a loop.
I have Z mapped to the folders where i need search new files and i try with the bat in this location and the desktop but the result is the same black window.
Thanks again for your help aGerman.
I think that the code come in to a loop.
I have Z mapped to the folders where i need search new files and i try with the bat in this location and the desktop but the result is the same black window.
Thanks again for your help aGerman.
Re: Batch to get file name
Of course you will see a black window.
First it saves all found files to variables.
After that it loops again and again to compare each found file if it existed before.
Only if a new file is found it will echo the file name.
Note, batch is very slow. If you have hundreds of files into the folder it takes a long time before the new file is found.
Regards
aGerman
![Wink :wink:](./images/smilies/icon_wink.gif)
First it saves all found files to variables.
After that it loops again and again to compare each found file if it existed before.
Only if a new file is found it will echo the file name.
Note, batch is very slow. If you have hundreds of files into the folder it takes a long time before the new file is found.
Regards
aGerman
Re: Batch to get file name
OK.
Now I understand all.
I'll try with a few folders and tell you feedback.
Thanks one more time aGerman.
Now I understand all.
I'll try with a few folders and tell you feedback.
Thanks one more time aGerman.
Re: Batch to get file name
Its seems that works properly.
In 4 hours try again a tell.
Im so tired and need sleep al least 4 hours.
Have a nice dreams aGerman.
In 4 hours try again a tell.
Im so tired and need sleep al least 4 hours.
Have a nice dreams aGerman.