How to change the current directory where the script runs when the script runs

Source: Internet
Author: User



If you want the script in Windows Script Host 5.6 to run when you need to modify the current directory where the script is running, build an Wscript.Shell object, and then set the CurrentDirectory Value property to the directory you want. For example, the following two lines will change the current directory to C:\Temp


Set Objshell = CreateObject ("Wscript.Shell")
Objshell.currentdirectory = "C:\Temp"


To verify, copy this script and save it to another folder that is not C:\Temp and run, you can see two popup windows, one is the current folder, and the other is the new current folder C:\Temp

Set Objshell = CreateObject ("Wscript.Shell")
WScript.Echo Objshell.currentdirectory
Objshell.currentdirectory = "C:\Temp"
WScript.Echo Objshell.currentdirectory


Note that if the directory does not exist, there is an error: the object ' CurrentDirectory ' method ' IWshShell3 ' failed.


Welcome to scan or search for my "Windows Automation Operations" public number, and I will regularly publish the knowledge of Windows Automation operations on a daily basis for you to discuss.


650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/76/25/wKiom1ZLPSeCU-ZbAABsCkHlBCM246.jpg "title=" QRCode _for_gh_394ccb413d36_258.jpg "alt=" Wkiom1zlpsecu-zbaabsckhlbcm246.jpg "/>

This article from "Johnny" blog, declined reprint!

How to change the current directory where the script runs when the script runs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.