How to get the details of a file on Windows - windows

If you open the properties of a file in Windows, there usually is a Details tab. I want to access the information on this tab, but I don't know how.
Is there a module for it? Does someone has a code sniplet?
I tried to work with Win32::File's GetAttributes, but these are not the attributes I was looking for.

use Win32::OLE;
my $objShell = Win32::OLE->new("Shell.Application") or die;
my $objFolder = $objShell->NameSpace($myDir) or die;
my $objFile = $objFolder->ParseName($fileName) or die;
while ( $i <= 34 )
{
my $propertyName = $objFolder->GetDetailsOf($fileName,$i);
my $propertyValue = $objFolder->GetDetailsOf($objFile,$i);
print "$i -- $propertyName -- $propertyValue\n";
$i++;
}

You can instantiate a COM "Shell.Application" object. It exposes a .NameSpace(folder) method that returns a reference to the name space of the indicated folder, which holds the information you need. The retrieved instance holds a Items collection with references to each of the files in the folder, and a .GetDetailsOf(file,property) to retrieve each of the values seen in the details tab and explorer columns.
Sorry i have no idea of perl, so i can not include any working code.

Related

change a autoloaded variable in codeigniter framework

I need to change a variable which is saved over the autoloader function.
Inside of a existing class (named "app") I can check if the variable is set.
$this->options[$name];
Now I want to change the value of these autoloaded variable, inside my app.php class in this way
---
echo"old value: ".$this->options[$name].")";
$this->options[$name] = $value;
echo "new value:".$this->options[$name];
return true;
...
for this, i get the correct new value.
The problem is, that it seems that this new value is not updated for the rest of the script!? If i access this variable later, i get the old value!?
What i do wrong?
The only "variables" that persist across different pages/loads/refreshes .etc. are those that are stored in a session variable, cookie or database.
To reiterate; this:
echo"old value: ".$this->options[$name].")";
$this->options[$name] = $value;
echo "new value:".$this->options[$name];
return true;
only affects the current instance at run-time (you can look at this as a page view). It will not persist. Same goes for config value changes in CodeIgniter.
Your only method is using some sort of file/database based storage.

Filling web form via PowerShell does not recognize the values entered

Working as a QA I need to fill in a lot of applications through a web form.
Idea is to have the personal data in some xls/txt/whatever file, read the file and use Powershell to feed data to the browser.
When I use the code below to fill in the form in IE, even though it seems to work fine, I get an error when submitting the form that no data was entered.
Any ideas or suggestions how to get past this would be much appreciated
Sadly my resources are limited to Powershell 2.0. Selenium or any other "more sophisticated" tools are out of question at least for now.
validation error here
$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("MyURL")
$ie.visible = $true
while ($ie.ReadyState -ne 4){sleep -m 100}
Function ClickById($id) {
$ie.document.getElementById($id).Click()
}
### Základní údaje
$FnId = 'personalData.firstName'
$LnId = 'personalData.lastName'
$PhoneId = 'personalData.mobilePhone'
$EmailId = 'personalData.email'
$DataAgreementCheckBox = 'application.personalDataAgreement'
$SubmitfwdId = 'forward'
$Values = "Ublala", "Pung", "222333444", "ublala#pung.com"
$Ds1Elements = $FnId, $LnId, $PhoneId, $EmailId
$j = 0
foreach ($El in $Ds1Elements) {
$ie.document.getElementById($El).value = $values[$j]
$j++
}
ClickById $DataAgreementCheckBox
ClickById $SubmitfwdId
Thanks for the suggestion but it did not work as the form seemes to be stupid in many ways.
Anyway I used your advice for the focus when going with SendKeys method and it did the trick.
At the beginning I needed to load this assembly
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
and then changed the loop accordingly to use the SendKeys method
$j = 0
foreach ($El in $Ds1Elements) {
$ie.document.getElementById($El).focus()
[System.Windows.Forms.SendKeys]::Sendwait($values[$j]);
$j++
}
And tradaaaa the form is filled and nobody is complaining :)
Sometimes website forms will wait until the input box has lost focus to pre-validate the value before submitting the form. The text boxes may never get focus if you are manually setting the values in the background so the form believes that you haven't actually entered any values.
You may be able to get around this by manually focusing each text box in turn, and then focusing the submit button before clicking it. Each element in the $ie.Document should have a focus() method you can use.

Magento programmatically creating attribute options - escaping

I'm using a script to programmatically create attribute options - the code is as follows:
echo "Creating option ....\n";
$attr_model = Mage::getModel('catalog/resource_eav_attribute');
$attr = $attr_model->loadByCode('catalog_product', $key);
$attr_id = $attr->getAttributeId();
if (!$attr_id){
echo "Cannot find Attribute $code\n";
return 0;
}else{
$option['attribute_id'] = $attr_id;
$option['value'][$value][0] = $value;
$option['value'][$value][1] = $value;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($option);
}
And for most values it's working absolutely fine.
However certain values are not being created - it's not throwing any errors, but it doesn't create the options.
One example is 55 mg/kg, which makes me suspect that it's an escaping issue.
Are there any particular escaping rules that I need to follow for this?
Having dug into this further, I've found out that if the array key you use in the $option['value'] array starts with a number, Magento treats this differently as part of the addAttributeOption() call (casting it as an (int), and then assuming you are editing an existing attribute option)
Ensuring the array key doesn't start with a number (I did this by pre-pending 'opt' onto the key) solves the issue.

My FormIt hook gets cached and it's screwing up every run after the 1st

I have the following snippet code hooked up to a FormIt email form:
$tv = "taken" . (int)$hook->getValue('datetime');
$docID = $modx->resource->get('id'); //get the page id
$page = $modx->getObject('modResource', $docID);
$current = (int)$page->getTVValue($tv);
if (!$page->setTVValue($tv, $current + 1)) {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'There was a problem saving your TV...');
}
$modx->setPlaceholder('successMessage','<h2 class="success">'.$current.'</h2>');
return true;`
It increments a template variable every time it is run and outputs a success message (although right now I'm using that functionality to output a debug message instead). The problem is, it only increments the TV once after saving the snippet, thereby refreshing the cache. Normally I would call the snippet without cache by appending ! to its name, but that doesn't appear to work for FormIt hooks. How can I get this code to work? Right now I'm running the entire page as uncacheable, but that is obviously suboptimal. Perhaps, there's a way to hook a snippet in an uncached manner? Call a snippet from within a snippet as uncached?
I'm doing something similar - but to count page loads, it looks to me like you are missing the last little bit: $current->save();
<?php
$docID = $modx->resource->get('id');
$tvIdm = 32;
$tvm = $modx->getObject('modTemplateVar',$tvIdm );
$tvm->setValue($docID, $tvm->getValue($docID) + 1 );
$tvm->save();
Try add this before you save $tv object
$tv->_processed = false;
It's derived from modElement's property it extends.

How do I get the suffix (in code) that is being used for urls?

Magento can add a suffix that is defined by the user to append onto urls. I want to get that suffix from my code. Does anyone know an easy way to do this?
If it's stored in the configuration area, then you access it just as you would any other configuration value, by using Mage::getStoreConfig($config_path) where $config_path is defined in the system.xml of the module that defines it.
If you're not sure of the $config_path, then I usually cheat and inspect the textbox/dropdown in the configuration section, take a look at the id, e.g. dev_log_file, and translate it to dev/log/file. You'll need to use some intelligence when there are multiple _ though :)
Nick's answer is good but the actual answer to this question is:
$suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();
If I am not mistaken, here is the code ( because I don't understand what you want with URL )
<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();
$url_parts = split('[/.-]', $currentUrl); // escape characters should change based your url
echo $url_parts[0]; //check here
?>
complete product url:
$productId = ***;
$productUrl = Mage::getBaseUrl().Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore()).Mage::helper('catalog/product')->getProductUrlSuffix();

Resources