I have created a batch file which is supposed to keep track of the opened PDF files on my system.As soon as someone opens the PDF file,the name of the file as well as time of access is recorded in a log file.
Here is code of my batch file:
#echo off
echo FILE ACCESSED %1 >> I:\Batch\log.txt
echo TIME OF ACCESS %TIME% >> I:\Batch\log.txt
"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %1
EXIT
I have also set up this batch file as the default application fr the PDF files to open with.
Now,the problem is,as soon as I open any PDF file,many cmd windows start opening and closing unendingly. Please suggest some remedy.
Thanks....
#echo off
copy %1 %1.tmp
echo FILE ACCESSED %1 >> I:\Batch\log.txt
echo TIME OF ACCESS %TIME% >> I:\Batch\log.txt
"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %1.tmp
del %1.tmp
EXIT
Related
I'm moving a task from manual to automatic
I'm well aware that you can't check for errors when doing this, but that's not my goal.
My code works as expected, but I'm missing... something
I need to let the user know that after I've put the file in the FTP location, that it was uploaded and they no longer need to wait for the file.
I've done this up to now by blagging the user, once the command has run, they just get told it's worked
#echo off
REM Generates the script
echo open 000.000.000.000> temp.txt
echo username>> temp.txt
echo password>> temp.txt
echo lcd "N:\line\line\line">> temp.txt
echo put file.txt>> temp.txt
echo quit>> temp.txt
REM Open FTP and run the script above
ftp -s:temp.txt
REM Remove the temp file
del temp.txt
REM Display confirmation
msg %username% "File sent to FTP"
Any help is greatly appreciated. I will add any more info if needed
You have to download the file back to see if it was correctly uploaded and do fc.
For unattened file download via ftp look at robvanderwoude's ftp. Don't forget that when saving the downloaded file it should have different name than the one you were uploading originally.
Then simply compare the files you have via fc command like this:
#echo off
fc c:\temp.txt r:\temp_to_check.txt > nul
if errorlevel 1 goto error
goto :EOF
:error
echo "The file was uploaded and downloaded incorrectly"
Answer specific to my question for visual purposes:
REM Open FTP and run the script above
ftp -s:temp.txt
REM File check
fc "N:\line\line\TEST.TXT" "N:\line\line\check_location\TEST.TXT" > nul
if errorlevel 1 goto error
REM Remove the temp file
del temp.txt
REM Display confirmation
msg %username% "File has now been sent to FTP"
goto :EOF
:error
msg "The file was uploaded or downloaded incorrectly"
I have automated file (.doc) uploads to an FTP server through BATCH files. I then run the BATCH file through the task scheduler every few minutes.
The below two batch files do the work for me:
upload.bat :-
open ftp.servername.com
username
password
cd FOLDER_NAME
binary
put D:\TEST\*.doc
bye
the above .bat file is called by the below .bat file,
startupload.bat :-
ftp -i -s:upload.bat
Now, the client removes files from the FTP once they are uploaded.
So, with above batch files, files are getting repeatedly uploaded.
Hence, my requirement is that each .doc file should be uploaded only once,
(OR,
may be, once a file is successfully uploaded to an FTP, it is shifted to another folder.)
Please help.
Thank you.
You can echo the directions into a text file then use -s?
Like the attached image
Then copy them to another folder and delete the originals?
#echo off
echo open serveraddress >ftp.txt
echo username>>ftp.txt
echo password>>ftp.txt
echo cd FOLDER_NAME>>ftp.txt
echo binary >>ftp.txt
echo "LCD D:\TEST\"
echo mput *.doc>>ftp.txt
echo bye>>ftp.txt
ftp -s:ftp.txt
del /f /q ftp.txt
copy "D:\TEST\*.doc" "C:\otherFolderPath\"
del /f /q "D:\TEST\*.doc"
::NOTES:
:: you can use ">>" to put the output of a command into a text file.
:: you can use ">" to put the output of a command into a text file. ">" Will clear a file if it exists, and will create a new file if it does not.
Note: If you want it to wait some time and then run again you can add this to the end of the script: Timeout /t 60 (That will wait 60 seconds, or until a user presses a key to continue)
I am using NetBeans 8.0.2 with PHP project. I have batch file called organizer.bat that configure to do some actions with the PHP source code.
Until now I run it manually after the code was changed.
I want that NetBeans will run my organizer.bat file automatically after I save a file in my project.
How can I configure such behavior?
One solution would be to have a batch file running in the background that periodically checks for new files in your project folder.
There's a lot of ways to do that. One way, for example, would be to output the directory files into a log file every 10 seconds.
If the new log file matches the old log file, then the contents of the directory are the same and the batch file does not need to be run.
The below commands will overwrite any existing log files.
:loop
cd C:\ProjectDirectory
xcopy logfile.log logfile2.log /f /y
dir > logfile.log
for %%I in (logfile.log) do set /a fs = %%~zI
for %%I in (logfile2.log) do set /a fs2 = %%~zI
if %fs%==%fs2% (echo "No changes in directory") else (echo "Changes in directory, run batch file.")
timeout /t 10
goto loop
I am trying to create a batch file that gets a zipped folder for that particular date (v_date) from the sftp site and then unzip them. The zip file contains five files that are text documents. I have written batch scripts that successfully get the zip file from the remote site and save a copy of it on the local drive. I need to incorporate the unzip part in to my script.
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
echo option batch continue>FTP_File_Get.txt
echo option confirm off>>FTP_File_Get.txt
echo open Target>>FTP_File_Get.txt
echo lcd "M:\Development\Data History\File" >> FTP_File_Get.txt
echo cd /Export/File >> FTP_File_Get.txt
echo get /Export/File/Filename_%v_date%.zip "M:\Development\DataHistory\Filename_%v_date%.zip">>FTP_File_Get.txt
echo exit>>FTP_File_Get.txt
M:\temp\apps\WinSCP\winscp.com/script="M:\Development\SFTPBatchFiles\FTP_File_Get.txt"
del FTP_File_Get.txt
This is my code to UNZIP:
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
cd "M:\Development\Data History\"
::SET v_file="M:\Development\Data History\Filename_%v_date%.zip"
::unzip -o %v_file%
"C:\Program Files\7-Zip\7z.exe" e "Filename_%v_date%.zip"
I need to move the extracted files (6 Files) into their respective folders, Any help is greatly appreciated
To unzip the files you can use this command line:
"C:\Program Files\7-Zip\7z.exe" e "filename.zip"
#echo off
set "source=%userprofile%\Desktop\basanta\Automation\a"
set "target=%userprofile%\Desktop\basanta\Automation\b"
FOR %%A IN ("%source%\*.gz") DO (
"%programfiles%\7-zip\7z.exe" x "%%~A" -o"%target%\%%~pA"
del "%%~A" /Y
)
Use the above code by saving it to .bat file extension
Remember %userprofile% is for the directory, %programfiles% for the program files set as a variable in windows
hope that helps
I have a program in my FTP server to generate a file, which may take 3-5 minutes to complete and also I knew the name of the file which i being created by my program. Now, once I initiate the program in my server, I have keep checking until the file is created. Once it is created, I am using the below batch script to ftp the file to my local desktop.
#ftp -i -s:"%~f0"&GOTO:EOF
open 10.100.16.111
username
password
lcd c:\
cd root/output_folder
binary
mget "*partial_file_name*" REM mget using wildcard search
disconnect
bye
This script works fine for me. But the problem is, I need modify this script as such, script should keep running until the file is generated. Because i don't know when the file creation will get completed. So, it will great if some one help/guide me to make a looping script which will wait until the completion of file creation and download the same file through FTP.
With this edit you can launch the batch file with the file name on the command line, like this:
ftpscript.bat "filename.ext"
Note that your lcd uses c:\ which is a restricted location in later versions of windows.
#echo off
>file.tmp echo open 10.100.16.111
>>file.tmp echo username
>>file.tmp echo password
>>file.tmp echo lcd c:\
>>file.tmp echo cd root/output_folder
>>file.tmp echo binary
>>file.tmp echo mget "%~1"
>>file.tmp echo disconnect
>>file.tmp echo bye
:retry
ftp -i -s:"file.tmp"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
del file.tmp
pause
More elegant solution is to use an FTP client that supports parametrized scripts or commands on command-line, such as WinSCP, to avoid creating a temporary script file.
Parametrized script
The batch file would be more or less identical as with the Windows ftp:
#echo off
:retry
winscp.com /script=script.txt /parameter "%~1"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
pause
The ftp script converts to following WinSCP script:
open ftp://username:password#10.100.16.111/
lcd c:\
cd root/output_folder
get -transfer=binary "%1%"
exit
Commands on command-line
You can also inline the commands the to the batch file:
#echo off
:retry
winscp.com /command ^
"open ftp://username:password#10.100.16.111/" ^
"lcd c:\" ^
"cd root/output_folder" ^
"get -transfer=binary ""%~1""" ^
"exit"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
pause
References:
Automating file transfers to FTP server;
Upload to multiple servers / Parametrized script.
Had you ever need to upgrade to the FTPS or the SFTP, just modify the session URL in the open command command accordingly.
(I'm the author of WinSCP)