Computer Hope

Microsoft => Microsoft DOS => Topic started by: Blisk on May 19, 2017, 05:15:52 AM

Title: how to use use relative path
Post by: Blisk on May 19, 2017, 05:15:52 AM
I try to copy a files from folders to one folder using relative path and doesnt work

copy all that log files to c:\new

c:\test\today\first\log\logfile.log
c:\test\yesterday\first\log\dovecot.log
c:\test\today\second\log\simple.log
c:\test\today\third\log\logfile.log
c:\test\yesteday\fifth\log\mail.log

I tried this
copy c:\test\..\..\log\*.log c:\new
copy "%cd%"log\log\*.log c:\new

nothing works
Title: Re: how to use use relative path
Post by: Computer Hope Admin on May 19, 2017, 05:26:28 AM
The relative path should be relative to what directory you are in when you run the command. So, it all depends on where you are running the copy command from. For example, if you were in the "c:\new>" directory and wanted to copy logs in "c:\test\today\first\log" using a relative path you would type:

copy ..\test\today\first\log\*.log

What this command does is first go back one directory since you're in "new" and then from the root goes into test\today\first\log

Any time you want to move back use ..\ and if there are more than one directories you need to go back you would need to go back multiple times. For example, if you were in c:\test\today\first\log and wanted to copy to the new directory using a relative path you would type:

copy *.log ..\..\..\..\new

Of course it would be easier in this example to use a absolute path and type:

copy *.log c:\new

Hoep that helps, also you may want to read the below page if you haven't already.

https://www.computerhope.com/issues/ch001708.htm
Title: Re: how to use use relative path
Post by: Blisk on May 19, 2017, 12:26:48 PM
Thanks
but how to go in directory forward not backward
If I have path like this
c:\test\yesteday\fifth\log\mail.log
I am in directory test and want to copy files *.log to c:\test1
than
copy c:\test\..\..\log\*.log c:\test1
but that doesn't work