Page 1 of 1

set current directory (CD) in a bat from another ref.txt

Posted: 29 Mar 2010 06:48
by jamesfui
for example, i always need to use the move command (move.bat) the destination i always set it to an output folder, but the Source always need to change...

:: All Document move command
CD "refer from ref.txt" :: <- source
move *.doc "c:\output\document\"

Is there a way to set the CD: current directory in this (move.bat) always refer from a text document (ref.txt) located in the desktop?

if possible, plz do not use the set /p var=
but use the CD instead.. cz mostly the full path is quite long to input it manually

thanks 8)

Re: set current directory (CD) in a bat from another ref.txt

Posted: 29 Mar 2010 12:50
by avery_larry
Do you mean that ref.txt already contains the path that you're interested in?

Code: Select all

for /f "usebackq tokens=" %%a in ("c:\path to ref\ref.txt") do cd /d "%%~a"

Re: set current directory (CD) in a bat from another ref.txt

Posted: 30 Mar 2010 06:38
by jamesfui
to make it more clear:

i have (move.bat) which Locate in c:\batch\records\move.bat
i would like to move all *.doc from c:\temp\doc\file1.doc file2.doc ...etc
to destination path for example, c:\permanent\destination\

so the destination path is permanent, but for the source i like to set the
CD (current directory) to always refer from a (ref.txt) located in the desktop!

so that whenever i want to change the source path, i just need to edit it in
the ref.txt in the desktop without going back to the move.bat script to re-edit
it everytime...

so basically, is it possible to put a script in the move.bat that reads the source path from the desktop ref.txt & set it as CD (current directory)?

thanks :)

Re: set current directory (CD) in a bat from another ref.txt

Posted: 31 Mar 2010 10:53
by avery_larry
That's what I did.

Re: set current directory (CD) in a bat from another ref.txt

Posted: 01 Apr 2010 03:40
by jamesfui
Sorry but it seems not working!!
Any other scripts can use?
thanks :(

Re: set current directory (CD) in a bat from another ref.txt

Posted: 05 Apr 2010 09:37
by avery_larry
Oops. Mixed up tokens and delims:

Code: Select all

for /f "usebackq delims=" %%a in ("c:\path to ref\ref.txt") do cd /d "%%~a"

Re: set current directory (CD) in a bat from another ref.txt

Posted: 05 Apr 2010 09:47
by jamesfui
this time is working perfectly!!

THANKS!! :mrgreen: