i want to watch a folder on my Win7 64bit Machine for new pdf files - and print them autmatically when there is a pdf file in the folder. After printing, the pdf file should be moved in a subfolder. So, after some google research i did a small batch file.
cd "D:\print"
for %%i in (*.pdf) do (
"C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" /print "%%i"
timeout /T 10 /nobreak
move D:\print\*.pdf D:\print\printed
echo %%i
)
I stored this in folder d:\print as print.cmd . When i start the cmd by doubleclick, my printer starts working and the pdf file moves to the subfolder i defined (D:\print\printed).
To watch the folder, i had the idea to create a sheduled task that repeat this cmd-script all 5 minutes.
BUT:
This dont work, when the script is started via scheduled tasks, the printer is not working - the "movement" of the file instead, is working.
I entered in the scheduled task:
Program: C:\Windows\SysWOW64\cmd.exe
Argument: /c"d:\print\print.cmd"
Any idea, why i cant acces the printer via the scheduled task?
The printer is connected via usb.
Hope i could provide necessary information! Thanks for your answers!
Change this line: move D:\print\*.pdf to move /Y D:\print\%%i
Point the scheduled task to actually start your batch file instead of calling cmd and putting the path to your script in the arguments.
You could also edit the batch file and code it to loop every 5 minutes so you only have to start it once:
PushD %~dp0
:start
for %%i in ("D:\print\*.pdf") do (
"C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" /print "%%i"
move /y "%%i" "D:\print\printed"
echo %%i
)
timeout /T 300 /nobreak
goto start
Related
I have legal .strm files of different TV Shows in a folder named TV Shows. Each strm file of each episode is stored in different subfolders.
I would like to run a certain VBScript before these strm files are played.
Then I have a different folder named MOVIES. Again, I would like to run a VBScript before these strm files are played. But this VBScript is a different one.
How would I do that?
Platform is Windows.
Thanks!
If you're looking to open or do something to each file based on extension, An easy way to do this is to use an for loop with /R to search all sub-directories for an *.strm file.
#ECHO OFF
SET "LOC=C:\Folder"
CD %LOC%
FOR /R %%A IN (*.strm) DO (
Rem | Do something with each file.
Start cmd.exe /C "notepad.exe "%%A""
)
Echo No More Items Found!
pause
goto :EOF
%%A will return the file path.
Start cmd.exe /C "" will start a CMD command. (Replace with your code)
notepad.exe "" will open the file (Used as an example)
EDIT:
So you're looking to check if the file exists then if true run the script? Bellow should solve that.
#ECHO OFF
If exist (C:/Path/file.strm) (
Rem | File exists, run script
Echo Do something
)
GOTO :EOF
I'm quite new to batch and I'm currently trying to run some Powerpoint presentations one after another. The thing is that I want it to look for all presentations that exists in my folder and then start one presentation after another.
I did this with this line
for %%f in (/f E:\PP\*.pptx) do start "" "C:\Program Files (x86)\Microsoft Office\Office14\PPTVIEW.exe" /F "%%f"
The problem now is that it runs every presentation at the same time. I kind of expected this already but I don't know how to manage that it does what I want to do.
Maybe you can help me. Thanks a lot.
This will give you one file, give a timeout of 5 seconds, open the next.
#echo off
for %%f in (E:\PP\*.pptx) do (
start "" "C:\Program Files (x86)\Microsoft Office\Office14\PPTVIEW.exe" /F "%%f"
timeout /t 5 >nul
taskkill /IM "PPTVIEW.exe"
)
keep in mind, this will open each 5 seconds after each other, but will not close the previous one, for that you need to run taskkill on the previous, before opening the new one.
For autoexit on a presentation (using powerpoint):
goto Options > advanced > untick the "end with blackslide" tickbox then simply run this code:
for %%f in (E:\PP\*.pptx) do start /w "" "C:\Program Files (x86)\Microsoft Office\Office14\PPTVIEW.exe" /F "%%f"
So now i have 2 .bat files. one copies some file if it was updated ( robocopy C:\location C:\destination) and another one that executes a some kind of .exe file (start c:\BAT\fraps.exe) , now what i need is maybe a one file, so that WHEN a file was copied using "robocopy" the executive file would run automaticaly. So maybe there is a way to merge them into one or smth.
Errorlevels are set by robocopy: errorlevel 1 means that a file was successfully copied.
robocopy C:\location C:\destination
if errorlevel 1 if not errorlevel 2 start c:\BAT\fraps.exe
Here is proof of concept code - following extended comments:
#echo off
md test1
:loop
>test1\testfile.txt echo aaa
robocopy test1 test2
if errorlevel 1 if not errorlevel 2 pause
del test1\testfile.txt
goto :loop
Use /WAIT option, when the application is stared then it will wait until it terminates.
Use /B option, when application is started then it will not create a new window.
Example:
start /wait Command CALL D:\YourFirstScript.bat
start /wait program.exe
start /wait Command CALL X:\YourSecondScript.bat
It's a good idea to print a message before and after.
Example:
ECHO Starting program.
start /wait program.exe
ECHO Finished.
See below link for more details.
How do I launch multiple batch files from one batch file with dependency?
Note: When you run script as administrator then you need to set full path as the default is set to "C:\Windows\System32".
The easiest way to set is
start %~dp0Directory\program.exe
See for details about "%~dp0" here
What does %~dp0 mean, and how does it work?
This is my first post and I hope that this will help you.
I have been using Robocopy to backup files and now i need to do something like this
"robocopy [D:\test1\21-09-2013\sample.txt] [destination]"
here i have a lot of folders as Test1,test2,...testn. and beneath every test folders there are date wise folder.
So i got the below answer to copy current dated folder by skipping its parent directory.
#ECHO OFF &SETLOCAL
set "mydate=%date:~10,4%_%date:~4,2%_%date:~7,2%"
for /d %%a in (D:\test*) do
(
if exist "%%~a\%mydate%\"
(
robocopy %%~a\%mydate% E:\backup\%date:~10,4%_%date:~4,2%_%date:~7,2%\ /xo /LOG+:file /TEE /NP /mon:2
)
)
It works fine without that monitor and if i use monitor, it stops with the first parent directory i.e test1 and waits for 2 changes.
What i exactly want is, It should copy the available(current dated) folders from all parent directory(test1,test2,..testn) and then it should monitor and run again with the changes. Also I couldn't run this if i scheduled this in Windows task scheduler. Requesting further help....
Here the code is essentially the same as in your question, with the addition of a timeout command (vista and higher) that waits for 900 seconds/15 minutes and then runs the batch file again by branching to the :loop label.
#echo off
setlocal
:loop
set "mydate=%date:~10,4%_%date:~4,2%_%date:~7,2%"
for /d %%a in (D:\test*) do (
if exist "%%~a\%mydate%\" (
robocopy "%%~a\%mydate%" "E:\backup\%date:~10,4%_%date:~4,2%_%date:~7,2%" /xo /LOG+:file /TEE /NP
)
)
timeout 900
goto :loop
I have task schedule for backup directory list of wwwroot. For that I have written batch file.
for /F "tokens=1-3 delims=: " %%i in ('time /t') do set Hma=%%i%%j%%k
set yyyymmdd=%date:~10,4%%date:~4,2%%date:~7,2%_%Hma%
set FolderPath=D:\SystemBackup\DirListFiles\
dir c:\inetpub\wwwroot /s /o-d > %FolderPath%\DirList_%yyyymmdd%.txt
batch file will do correct at this point but after this
echo "Upload To FTP Start"
cd /d c:\Program Files (x86)\WinZip\
winzip32.exe /autorunjobfile d:\BackupScript\DirList.wjf
echo "Upload FTP Complete !"
cd /d %FolderPath%
del DirList_%yyyymmdd%.txt
Not working well. It does not winzip well and also not send to ftp server.
From forum of Winzip, I found that if you want to run winzip job in batch mode than first time should run manually and winzip open one dialog box. Tick to do not ask again checkbox. so that task scheduler do not wait for prompt.
for the first part, winzip not working, you need to review your winzip job file and post here the failing part.
EDIT Ooops I was wrong.... you don't need to enclose the path in quotes. Sorry.
CD needs you to enclose the path in quotes, instead of
cd /d c:\Program Files (x86)\WinZip\
try
pushd "c:\Program Files (x86)\WinZip\"
for the second part, ftp not working, again you need to review your winzip job file and post here the failing part.