Gossamer Forum
Home : General : Perl Programming :

How to change a directory on windows via perl script

Quote Reply
How to change a directory on windows via perl script
How to change a directory on windows via perl script

I wanna mount a share on windows via perl script.so writing a perl script.But i am not able to change directory via scripting.

I have used:-

system("dir");

which gives the list of directories in the drive i am.This command works well.

Now i want to move from c drive to z drive via perl script.I am using:-

system("chdir /D z:");

also tried---
system("z:");
`z:`



but no success...

can some one help me please?????
Quote Reply
Re: [trupti] How to change a directory on windows via perl script In reply to
Code:
chdir('C:\path\to\go\to');

(been a while since using a NT machine, but you *may* need to do some escpaing too - i.e : chdir('C:\\\path\\\to\\\go\\\to');

Then, when using:

Code:
system()

..it should be in that directory.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [trupti] How to change a directory on windows via perl script In reply to
Thank you Andy...

I tried to do that...but it did not work...Frown..

Also,
I did not get you,when u said system()...u should be working in that dir...
Quote Reply
Re: [trupti] How to change a directory on windows via perl script In reply to
Hi,

So you tried something like:

Code:
#!C:/perl/perl.exe

print "Content-Type: text/html \n\n";

chdir('C:/test_directory');
print system('dir');

..and that doesn't work? If not, try:

Code:
#!C:/perl/perl.exe

print "Content-Type: text/html \n\n";

chdir('C:\test_directory');
# or *maybe*
# chdir('C:\\\test_directory');
print system('dir');

Also, try running it via a "cmd" prompt, to see how it works - something like:

Code:
c:/perl.exe test.cgi

Cheers

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [trupti] How to change a directory on windows via perl script In reply to
Hey...Andy...the first script worked...Smile

Thanks a zillion..u made my day...I was stuck right from morning on this.....

I went to z: using chdir('z:' ) from c:/---
system('md newdir');
system('dir');-----gave me the list of all files in z:...

Thank you once again....Smile ..

Only thing is that i am not able to stay in that drive (z:/) after script execution...

i come back to the c:/...

Last edited by:

trupti: Dec 10, 2008, 3:40 AM
Quote Reply
Re: [trupti] How to change a directory on windows via perl script In reply to
Hi,

Glad that worked Cool

Regarding your other question - I'm afraid I don't know. Could be that you have to keep re-doing the chdir()every time, before running a command :|

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] How to change a directory on windows via perl script In reply to
Code:
chdir('C:\test_directory');
# or *maybe* #
chdir('C:\\\test_directory'); print system('dir');

It should be:

chdir("C:\\test_directory");

Last edited by:

Wychwood: Dec 11, 2008, 2:26 AM
Quote Reply
Re: [Wychwood] How to change a directory on windows via perl script In reply to
As I said, its been a long time since I've done that on an NT machine :P (or windows, full stop). I think it would have been 3, if not 4 years ago - so I'm a little rusty ;)

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] How to change a directory on windows via perl script In reply to
If you're a perl programmer who uses regexes I'd have thought you'd know all about escaping.