Search code examples
batch-filecygwincommandcd

Problem while using cd command in cygwin based windows batch script


I am facing a problem in windows batch script. I have installed cygwin in my system. So i am using bash commands inside my batch script for efficiency. Consider the below command

cp -rf D:/Ashok E:/Data
E:
cd E:/Data
cd E:/Data

Output is

c:>sample.bat
c:>cp -rf D:/Ashok E:/Data
c:>E:
E:>cd E:/Data
E:/Data>cd E:/Data
The system cannot find the specified path

While in the same folder (E:/data), i am trying to do the cd, that time i am getting error message. Because it treated that entire "E:/Data" as a folder name. How to get rid of this problem. What we can do to solve this problem.


Solution

  • Using the proper back slash in the cd command will solve the problem. But cp command is supporting both the slashes.

    c:>sample.bat
    c:>cp -rf D:/Ashok E:/Data
    c:>E:
    E:>cd E:\Data
    E:/Data>cd E:\Data