|
|||||||
| Other Discussion and technical support for any other scripting methods. |
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
BAT file
i need to copy periodically all files having .txt extension from one directory into another without any alerts or popups - so to say 'in silent mode'. i need to do it in Windows (from 'current folder' where the *.bat file is into 'C:\test'). i do not know how to write *.bat files.. can anybody help me?
thanks in advance
__________________
x = x + 1; my wife calls it "absurd" |
|
#2
|
|||
|
|||
|
You need to put in your bat file following line:
Code:
@copy/y c:\path\to\*.txt c:\new\path > c:\log\path\log.txt |
|
#3
|
||||
|
||||
|
thank you very much for reply! i've done everything according to your instruction. as the result the log.txt file is created in the destination dir but no any file was copied. log.txt contains some unreadable text (encoded like some 'blue screens' if you know what i mean). i suspect that the bat file must contain some kind of a loop (like we do it in PHP or JavaScript) but i don't know what syntax is used for such files. is '@copy/y' equal to a loop?
and one more note (my bad,sorry): if the destination dir not empty i'd like this bat file not to overwrite all the files with the same names. this bat file is expected to be executed periodically (1 time per an hour, for example). can you please teach me how do i change the code to make every copying cycle to put files in separate subdir named by timestamp or smth like that? thanks in advance
__________________
x = x + 1; my wife calls it "absurd" |
|
#4
|
||||
|
||||
|
ok it works now
Code:
@copy/y *.txt c:\test > c:\test\log.txt $t_stamp = date('U'); // this is going to be unique every time we call the function $subdir_name = '../workdir/' . $t_stamp; how do i the same using bat files syntax? i would like to do as below: Code:
$t_stamp = bla-bla-bla // unique @copy/y *.txt c:\test\$t_stamp > c:\test\$t_stamp\log.txt thanks in advance
__________________
x = x + 1; my wife calls it "absurd" Last edited by Padonak; 07-16-2010 at 04:40 PM. |
|
#5
|
|||
|
|||
|
In your case batch commands wouldn't be powerful enough - you'd need to use another environment - Windows Script Host or another engine (PHP, for example) or even build yourself an .exe program using Delphi or C(++) compiler.
Maybe someone could help Padonak with Windows Scripting? |
|
#6
|
|||
|
|||
|
I would think it would be much easier to use php cli rather than try to learn a new scripting language. You can call php scripts the same way as bat files as long as the cli is in the registry to handle php files (for windows at least, much easier in linux). This would have the added benefit of working across multiple OSes.
|
|
#7
|
||||
|
||||
|
criterion9 php is not installed on the computer where these copying operations are going to be executed. ok i see i must explain the whole problem. a very good friend of mine has a small shop. he suspects one of his managers in disclosing proprietary information to competitors. he also suspects that this man is doing it through the qip instant messanger. he tried to look through the History files when the manager was absent but found all the History erased. he asked me to help him with this problem because this may cause serious business troubles to his shop.
we cant use keyboard sniffers or anything like that because of antivirus application which options are passworded. i decided to use a .BAT file which is going to be executed periodically by the Windows Task Manager just to copy the History files into another directory for future investigation. i do not really need to learn a new scripting language. all i need is somebody to help me to write this .BAT file. that's the naked truth guys ;-)
__________________
x = x + 1; my wife calls it "absurd" Last edited by Padonak; 07-17-2010 at 01:32 PM. |
|
#8
|
|||
|
|||
|
I would think it would be easier and probably even more fool proof to just install php and run a cli script that forwards the results to a server (using curl or whatever).
Barring that easier method you can use any command you could execute in dos or cmd.exe. http://www.tech-recipes.com/rx/956/w...ddyyyy-format/ http://weblogs.asp.net/whaggard/arch...18/423029.aspx http://support.microsoft.com/kb/555314 |
|
#9
|
||||
|
||||
|
ok thanks i'll check the links. i've never used php this way before lol
__________________
x = x + 1; my wife calls it "absurd" |
|
#10
|
|||
|
|||
|
Those links were for how to use the current date in windows bat files. When you install PHP the default is to add the cli handler to the registry so executing "php yourFile.php" will run the file. This would allow you to do whatever you wanted with the data in question in a language you are more familiar with (email the data, send to a database, look for suspicious data, etc).
|
|
#11
|
||||
|
||||
|
thanks a lot ;-)
__________________
x = x + 1; my wife calls it "absurd" |
|
#12
|
|||
|
|||
|
And more easier would be to get an already written by somebody else vbscript than installing PHP only for a single task... Of course, if expecting to need additional scripts in future, then yes, PHP would be better option.
Anyway, how come the owner of the shop doesn't have full access to a shop's computer? (The antivirus' password in this particular case). |
|
#13
|
||||
|
||||
|
Quote:
as for the antivirus' pass - this antivirus was installed by the manager himself. it is not that big megamarket but a small car spare parts shop. there are only three of them - the owner(director), my wife(manager), and the suspect(manager/stockman). the owner is a friend of mine and my wife works in his shop that's why the last thing i'd want is the shop in troubles ;-) of course the owner may inspect every computer without asking a user permission but he asked me to help him to discover what's going on secretly to get some real evidence.
__________________
x = x + 1; my wife calls it "absurd" |
|
#14
|
||||
|
||||
|
the final solution looks like the following:
1 i created service.cmd file which contains this code in the target directory Code:
@echo off @set NEWDIR=%date:~-4,4%%date:~-7,2%%date:~-10,2%_%time:~-11,2%%time:~-8,2%%time:~-5,2%%time:~-2,2% md > nul c:\test\%NEWDIR% @copy/y *.qhf c:\test\%NEWDIR% > c:\test\%NEWDIR%\log.txt Code:
var WSHShell = WScript.CreateObject("WScript.Shell");
WSHShell.Run("service.cmd",0);
testing on my home computer has shown perfect result. thank you all guys for helping and guiding me ;-))
__________________
x = x + 1; my wife calls it "absurd" |
|
#15
|
||||
|
||||
|
I hate to jump i this late but XCOPY might be a better choice than COPY. But if you are using WScript anyway then you might also just do the thing with the Windows file system object.
__________________
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.” —Tim Berners-Lee, W3C Director and inventor of the World Wide Web |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|