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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

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

#1 Post by jamesfui » 29 Mar 2010 06:48

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)

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

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

#2 Post by avery_larry » 29 Mar 2010 12:50

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"

jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

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

#3 Post by jamesfui » 30 Mar 2010 06:38

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 :)

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

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

#4 Post by avery_larry » 31 Mar 2010 10:53

That's what I did.

jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

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

#5 Post by jamesfui » 01 Apr 2010 03:40

Sorry but it seems not working!!
Any other scripts can use?
thanks :(

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

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

#6 Post by avery_larry » 05 Apr 2010 09:37

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"

jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

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

#7 Post by jamesfui » 05 Apr 2010 09:47

this time is working perfectly!!

THANKS!! :mrgreen:

Post Reply