www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > Other

    Other Discussion and technical support for any other scripting methods.

    Reply
     
    Thread Tools Rate Thread Display Modes
      #1  
    Old 07-15-2010, 03:57 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    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"
    Reply With Quote
      #2  
    Old 07-15-2010, 04:44 PM
    MGenev MGenev is offline
    Registered User
     
    Join Date: Jul 2010
    Location: Sofia, Bulgaria
    Posts: 40
    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
    Replace "c:\path\to" and "c:\new\path" with appropriate source and destination directories. Replace "c:\log\path\log.txt" with desired path and filename - this will be the "log file" containing the output from the last operation (otherwise it will be displayed on screen).
    Reply With Quote
      #3  
    Old 07-16-2010, 12:27 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    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"
    Reply With Quote
      #4  
    Old 07-16-2010, 04:22 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    ok it works now

    Code:
    @copy/y *.txt c:\test > c:\test\log.txt
    one question else. how do i set a variable which contains the timestamp? in php for example we do:
    $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
    where can i get some reference on bat files syntax or smth like that? what language are such files written in? and how do i hide or (the best way) make not appear at all an empty black cmd-window which pops up as the bat file is being executed?

    thanks in advance
    __________________
    x = x + 1; my wife calls it "absurd"

    Last edited by Padonak; 07-16-2010 at 04:40 PM.
    Reply With Quote
      #5  
    Old 07-16-2010, 11:03 PM
    MGenev MGenev is offline
    Registered User
     
    Join Date: Jul 2010
    Location: Sofia, Bulgaria
    Posts: 40
    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?
    Reply With Quote
      #6  
    Old 07-17-2010, 09:30 AM
    criterion9 criterion9 is online now
    B.S. CIS
     
    Join Date: Jan 2009
    Posts: 2,405
    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.
    Reply With Quote
      #7  
    Old 07-17-2010, 01:30 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    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.
    Reply With Quote
      #8  
    Old 07-17-2010, 01:59 PM
    criterion9 criterion9 is online now
    B.S. CIS
     
    Join Date: Jan 2009
    Posts: 2,405
    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
    Reply With Quote
      #9  
    Old 07-17-2010, 02:20 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    ok thanks i'll check the links. i've never used php this way before lol
    __________________
    x = x + 1; my wife calls it "absurd"
    Reply With Quote
      #10  
    Old 07-17-2010, 02:23 PM
    criterion9 criterion9 is online now
    B.S. CIS
     
    Join Date: Jan 2009
    Posts: 2,405
    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).
    Reply With Quote
      #11  
    Old 07-17-2010, 02:48 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    thanks a lot ;-)
    __________________
    x = x + 1; my wife calls it "absurd"
    Reply With Quote
      #12  
    Old 07-17-2010, 03:54 PM
    MGenev MGenev is offline
    Registered User
     
    Join Date: Jul 2010
    Location: Sofia, Bulgaria
    Posts: 40
    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).
    Reply With Quote
      #13  
    Old 07-23-2010, 03:06 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    Quote:
    Originally Posted by MGenev View Post
    ... how come the owner of the shop doesn't have full access to a shop's computer? (The antivirus' password in this particular case)...
    you know there are people... my english is not good enough but in russian they call such people 'far from something'. it means that this man does not understand the subject well. this shop owner is 'far from computers and everything of the kind' and that was my idea to look through the History of the instant messanger.

    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"
    Reply With Quote
      #14  
    Old 07-25-2010, 12:17 PM
    Padonak's Avatar
    Padonak Padonak is offline
    Registered User
     
    Join Date: May 2006
    Location: Russia, Rostov-on-Don
    Posts: 500
    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
    2 then i created service.js file in the same directory

    Code:
    var WSHShell = WScript.CreateObject("WScript.Shell");
    WSHShell.Run("service.cmd",0);
    3 i created a new scheduled job for the Windows Task Manager

    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"
    Reply With Quote
      #15  
    Old 07-25-2010, 01:10 PM
    Charles's Avatar
    Charles Charles is offline
    JavaScript Banned
     
    Join Date: Nov 2002
    Location: Baltimore, Maryland
    Posts: 11,948
    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
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:51 PM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.