change directory failing in cmd prompt - perl

I have two files :
perl file "Test.pl" at the location "C:\A1\A11\A12\A13\A14\A15"
bat file "TestBatch.bat" at the loc : "C:\A1\A11\A12\A13\B14"
The perl file "Test.pl" makes a call to the batch file "TestBatch.bat" and then the batch file should try to set the current path to be "C:\A1\A11\" and change the directory to "C:\A1\A11\A12\A13\B14"
But it fails saying the "System cannot find the path specified". I want it to change directory to "C:\A1\A11\A12\A13\B14"
Following is the code of both the files
Test.pl
my $abs_bat_file_loc = "C:\\A1\\A11\\A12\\A13\\B14\\TestBatch.bat";
system ($abs_bat_file_loc);
TestBatch.bat
set current_path=%CD%\..\..\..\..\
cd A12\A13\B14
Note : I ran the perl file in cmd prompt in following way:
cd C:\A1\A11\A12\A13\A14\A15
perl Test.pl
Any help is much appreciated. Thanks in advance!

Instead of
set current_path=%CD%\..\..\..\..\
cd A12\A13\B14
Why not replace it with
PushD %~dp0
this will force the working directory in the batch file to be the full location of where the batch file is located (eg; C:\A1\A11\A12\A13\B14)

Related

PowerShell: Open file via .bat script

imagine I have a files with certain extensions (for example '.abc').
The default program I set for files with this special extension is a batch script with powershell commands in it, so when I doubleclick the file, it runs the script. It works.
Now my question is, can I somehow get the file path of the .'abc' file I opened? Is there a command for this?
Thank you.
Inside of your batch file it should be possible to access the ".abc" file via parameter %1.
Per default Windows sends the filename of the file you doubleclick to the receiving program (or batch script) as parameter one.
Try this inside of your batch file (near the top) and pick what suits your needs:
echo param1: %1
echo param1 unquoted: %~1
echo drive: %~d1
echo drive and path: %~dp1
echo filename and extension only: %~nx1
set myparam=%~1
echo myParam: %myparam%
See the help documentation of for for the "%~..." syntax by executing for /? in a cmd.exe command window. (Or read here: What does %~dp0 mean, and how does it work?)

bat file to run perl script on all sub directories

I have a simple bat file that sets a directory and runs a perl on the directory.
cd Q:\Research\Images(new)\MuseumSpecimens\DBG\DBG_Specimens\DBG_ToBeRenamed
perl Q:\Research\Images(new)\MuseumSpecimens\DBG\DBG_Specimens\zbar\barcode.pl
I want to modify the bat file so that it runs the perl script on each sub directory within the directory (each folder within DBG_ToBe_Renamed) in this case. So far I have the following, but it isn't quite right.
FOR /R Q:\Research\Images(new)\MuseumSpecimens\DBG\DBG_Specimens\test\ %%G IN (.) DO perl Q:\Research\Images(new)\MuseumSpecimens\DBG\DBG_Specimens\zbar\barcode.pl
Thanks, I appreciate any help.
If it helps, the perl script reads barcodes from JPEGs and creates new files with the JPEG and associated RAW file renamed using the barcode value (https://github.com/psweeney-YU/reBar/blob/master/reBar.pl)
This should work:
for /D %%d in (Q:\Research\Images(new)\MuseumSpecimens\DBG\DBG_Specimens\DBG_ToBeRenamed\*) do pushd %%d && perl Q:\Research\Images(new)\MuseumSpecimens\DBG\DBG_Specimens\zbar\barcode.pl && popd

"No such file or directory" when executing Perl script

I have a 3D modal for cup.obj. I need to convert to .h file so I downloaded this http://heikobehrens.net/2009/08/27/obj2opengl/ And put cup.obj file to this folder. Then I run from terminal obj2opengl.pl cup.obj I didn't get .h file.
Ranganatha-GVs-Mac-mini:~ ranganathagv$ ./obj2opengl.pl cup.obj
-bash: ./obj2opengl.pl: No such file or directory
Ranganatha-GVs-Mac-mini:~ ranganathagv$
The obj2opengl.pl script probably hasn't the right permission set in order to be executable using the ./ syntax.
Two choices here, you can either:
Change the permission on the script using chmod +x obj2opengl.pl, and using ./obj2opengl.pl cup.obj should work from there on, or
Run the script using perl obj2opengl.pl cup.obj.
Hope this helps!

Can't exec No such file or directory

Merry Christmas to everybody. I'm having a dilemma with a perl script. In my script, I call another program with a system call, but I got this error:
Can't exec "./Classificador/svm_classify": No such file or directory at Analise_de_Sentimentos_mudanca.pl line 463.
I don't know if there is a problem in having my program in a different directory than the called program.
Another curious thing is that this script used to run normally in Ubuntu 10.10. But now I've changed to Mint 14. Is it missing some library?
Best wishes,
Thiago
The relative pathname ./Classificador/svm_classify is interpreted relative to the user's current directory, not the directory containing the perl script. You need to do one of the following:
The user must cd to the directory containing the perl script before running it.
The perl script should call chdir() to set the current directory to the directory where it's stored.
Put the absolute pathname in the script, instead of ./.
Does this "./Classificador/svm_classify" exists ?
Check the following :
1) to go the directory where this file lays - Analise_de_Sentimentos_mudanca.pl
2) run :
ll Classificador/svm_classify
3) show us the results

finding a files path in the command line

I am doing a batch scripting assignment where I have to call one script from inside another. I need the script to run the second script no matter where my lecturer saves these scripts. How would I do this. Is there some way to find the path of script inside the script and use that to execute the file. Any help would be great. I think I need to use %'s but i'm not sure.
The name of the script is Hello World.bat.
How would I copy Hello World.bat to the C:\ if I don't know which directory the lecturer has placed it in. what command/s would I use so that the copy would work regardless of the scripts location.
I don't see the "DOS" tag, but I'll assume that it is for now. If you want the entire path, you can get it by doing this:
echo %cd%
If you want just the last folder, this works (inside a .bat file):
for %%* in (.) do #echo %%~n*
Note that from the command line, the above command will work with single %'s:
for %* in (.) do #echo %~n*
If the script you are executing is calling other scripts in the SAME folder location, you can prefix the path statement with "%~dp0" or "%~dps0" but do not put a backslash between that and the name of the script you are calling. In other words, if script1.bat is calling script2.bat in the same folder, the statement in script1.bat would refer to "%~dp0script2.bat"
sorry about batch files, am not familiar, but in nix shell, there is the locate command which can return the path of the file , if you know the filename exactly and the name is unique.
like
name=$(locate filname)