Windows Script with Jscript error trying to move file

Posted on 2004-11-06
Last Modified: 2011-09-20
i get the following error when running the script provided below  the ciopy part works perfect the move part is the one that gives the error please help

Line 23
Char  2
Error  The system cannot find the file specified.

code 80070002
source (null)

this is the script please help

// Copy compressed backups to backups server then move originals to data folder.
// Plese note: all backslash's must be doubled, this is a becouse of the way Jscript deals with strings

var strPath = "Y:\\TransCompCasino\\";
var strDestPath = "\\\\backups\\DBbackups\\TransCompCasino\\";

var shell = new ActiveXObject("WScript.Shell");
var objFSO = new ActiveXObject('Scripting.FileSystemObject');

var objFolder = objFSO.GetFolder(strPath);
var nrFiles = objFolder.Files.Count;
var collectionFiles = new Enumerator(objFolder.Files);
while (!collectionFiles.atEnd())
   objFile = collectionFiles.item();
   if (objFile.Type == "RAR File")
      strFileName = objFile.Name;
                strCommand = "xcopy " + strPath + strFileName + " " + strDestPath + " /v /d";
      strCommand = "move /y " + strPath + strFileName + " " + strPath + "data\\";
Question by:m3mn0ck
    LVL 3

    Expert Comment

    Hi m3mn0ck,

    print the strcommand to the screen after you've constructed it. this should help you know why it doesnt work.

    Author Comment

    The string is working fine, actually if i just change the Move Comand to Xcopy (of course i remove the /y switch it works fine and copies the files. but it will not move them i get that error even if i run it without the /y switch
    LVL 3

    Accepted Solution

    have you  tried using proper jscript filesystem object stuff to do the move e.g.

    Sub ManipFiles
      Dim fso, f1, f2, s
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
      Response.Write "Writing file <br>"
      ' Write a line.
      f1.Write ("This is a test.")
      ' Close the file to writing.
      Response.Write "Moving file to c:\tmp <br>"
      ' Get a handle to the file in root of C:\.
      Set f2 = fso.GetFile("c:\testfile.txt")
      ' Move the file to \tmp directory.
      f2.Move ("c:\tmp\testfile.txt")
      Response.Write "Copying file to c:\temp <br>"
      ' Copy the file to \temp.
      f2.Copy ("c:\temp\testfile.txt")
      Response.Write "Deleting files <br>"
      ' Get handles to files' current location.
      Set f2 = fso.GetFile("c:\tmp\testfile.txt")
      Set f3 = fso.GetFile("c:\temp\testfile.txt")
      ' Delete the files.
      Response.Write "All done!"
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
    Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now