在perl脚本中获取%AppData%的路径

时间:2016-03-30 15:11:01

标签: perl

任何人都可以帮助解决这个问题:

use strict;
use warnings;
use Cwd;
use File::Copy;
use Win32;
use Config;
use Backticks;


#print "$^O\n";
#print "$Config{osname}\n";
#print "$Config{archname}\n";

#Win7Professional (32-bit) Service Pack 1
#Win8Professional (64-bit)
#print "\nOS: ", $osversion;

my $osversion = Win32::GetOSName();
#my $localConfPath = `\%localappdata\%`;
my $localConfPath = system("\%localappdata\%");
my $localConfPath = system(`\%localappdata\%`);

#print "$env:APPDATA\n";
exec(`\%localappdata\%`); if($@) {  print "$@\n";  }

#print "PO: $localConfPath\n";

我需要获得" localappdata"使用perl脚本的路径。而且基于Windows操作系统的输出也会更好。

" C:\用户\激光\应用程序数据\本地" " C:\用户\激光\应用程序数据\漫游"

1 个答案:

答案 0 :(得分:4)

使用以下

#!/usr/bin/perl

use warnings;
use strict;

my $localConfPath = $ENV{localappdata};
my $appdata = $ENV{appdata}; 

print $localConfPath;  #will print the app path - C:\users\xxx\AppData\local
print $appdata; #prints - C:\users\xxx\AppData\Roaming