I want to get the file list from a folder recursively in a table.
I tried the following:
function getStructure ( path )
local fileArray = readFilesAndFoldersFromPath( path ) -- returns table
for i = 1, #fileArray do
if fileArray[i].type == 'folder' then
getStructure ( fileArray[i].path )
end
end
end
getStructure( '/folder/example')
Which works. But now I also want the result in an multidimensional table like this:
[1] => file1
=> file2
[2] => folder1
=> file 3
=> file 4
=> folder 2
[3] => file 5
How to do this?
function getStructure ( path )
local fileArray = readFilesAndFoldersFromPath( path ) -- returns table
for i = 1, #fileArray do
if fileArray[i].type == 'folder' then
fileArray[i].folder_content = getStructure ( fileArray[i].path )
end
end
return fileArray
end
local myFolderStructure = getStructure( '/folder/example')
Related
If I try to declare a Mix with Boolean components:
my $mix= (True => 0.3, False => 0.7).Mix;
dd $mix; # OUTPUT: «Mix $mix = ("True"=>0.3,"False"=>0.7).Mix»
They use Pair syntax, which quotes automatically those bare identifiers. In order to avoid that, you either have to define the Pairs explicitly via Pair.new, or else use the fully qualified name.
my $mix= (Bool::True => 0.3, Bool::False => 0.7).Mix;
Is there any other way of doing that? A simpler way maybe?
You can use anything that isn't seen as a bare-word.
Fully qualified names work.
Bool::True => 1
The reason they work is bare-words don't have :: in them.
So you can just prepend :: as well.
::True => 1
You can use ::(…)
::(True) => 1
::('True') => 1
::< True > => 1
You can also use () around True.
(True) => 1
You could declare it backwards and use .antipair
( 1 => True ).antipair
( :foo ).antipair # (Bool::True) => 'foo'
If you don't mind getting a sequence you can use .invert, or .antipairs
# Seq.new( Bool::True => 1 )
( 1 => True ).invert
( 1 => True ).antipairs
# Seq.new( Bool::True => 1, Bool::False => 2 )
( 1 => True, 2 => False ).invert
( 1 => True, 2 => False ).antipairs
If True was a subroutine instead of a term, you could append ()
sub True ( --> True ){}
True() => 1
Then there is using Pair.new.
Pair.new( True, 1 )
Using parens as in (True) => 0.3 or the null pseudo-package as in ::True => 0.3 would be another option.
I have a query which I am trying to convert into yii2 syntax. Below is the query
SELECT project_id, user_ref_id FROM
(
SELECT `project_id`, `user_ref_id`
FROM `projectsList`
WHERE user_type_ref_id = 1) AS a WHERE user_ref_id = '.yii::$app->user->id;
I am trying to convert it into yii2 format like
$subQuery = (new Query())->select(['p.project_id', 'p.user_ref_id'])->from('projectsList')->where(['user_type_ref_id' => 1]);
$uQuery = (new Query())->select(['p.project_id', 'p.user_ref_id'])->from($subQuery)->where(['user_ref_id ' => yii::$app->user->id])->all();
It is giving an error like
trim() expects parameter 1 to be string, object given
How to I pass subquery as table name to another query
Not tested, but generally this is how it goes. You need to pass the subQuery as a table. So change ->from($subQuery) in the second query to ->from(['subQuery' => $subQuery])
$subQuery = (new Query())->select(['p.project_id', 'p.user_ref_id'])->from('projectsList')->where(['user_type_ref_id' => 1]);
Then
$query = (new Query())->select(['p.project_id', 'p.user_ref_id'])->from(['subQuery' => $subQuery])->where(['subQuery.user_ref_id ' => yii::$app->user->id])->all();
Here is my code
$fields = array("sku" => "TestM-F", "options" => ["product_option_id" => 330,"option_value_id" => 255 ]);
$isCreated = $this->store->createSku($fields);
$error = $this->store->getLastError();
print_r($error);
print_r($isCreated);
I getting error like this
[status] => 404
[message] => The requested resource was not found.
product_option_id & option_value_id already present in table.
TestM sku is already exist but I want to create another sku with new name like TestM-F and by using same product_option_id & option_value_id. (duplicate).
Try to Use
return Client::createResource('/products/' . $this->product_id . '/skus', $this->getCreateFields());
Is it possible when using FAL, to set the upload destination folder directly in the TCA column? My configuration looks like this at the moment:
'images_outdoor' => Array (
'exclude' => 1,
'label' => 'Outdoor: ',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('images_outdoor', Array (
'appearance' => Array (
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
),
'minitems' => 1,
'maxitems' => 6,
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
),
I have such columns in different TCAs and want their images to be saved in different folders. So a standard folder setting doesn't work here.
I know this one is old but here is a answer.
There are no supported way for TYPO3 6.2, but in the new TYPO3 7.6 LTS it should be possible to register a hook in your ext_localconf.php file, add this:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getDefaultUploadFolder'][] = 'VendorName\ExtensionName\Hooks\BackendUserAuthentication->getDefaultUploadFolder'
Create the file Classes/Hooks/BackendUserAuthentication.php and write something like this:
<?php
namespace VendorName\ExtensionName\Hooks;
classe BackendUserAuthentication {
public function getDefaultUploadFolder(Array $params, \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUserAuthentication) {
// Do what you wants here and return a object of \TYPO3\CMS\Core\Resource\Folder
}
}
The params array will contain this:
$_params = array(
'uploadFolder' => $uploadFolder, // The current \TYPO3\CMS\Core\Resource\Folder object, properly 1:/user_upload/
'pid' => $pid, // Page id
'table' => $table, // The table name
'field' => $field, // The field name
);
Now use the table and field name to change the upload folder - good look :)
Here is the original logic
(scrape_datas = ScrapeData.find(
:all, :conditions =>
"artist_status = 'NOT_FOUND'
AND blacklisted = 1
AND extracted = 0
and not EXISTS(
SELECT * FROM artist_name_suggestions where original = artist_name
)
I've been able to split up the first part better
scrape_datas = ScrapeData.where(
:artist_status => 'NOT_FOUND',
:blacklisted => 1,
:extracted => 0
)
Although having issues getting the "and not EXISTS" query into the mix
and not EXISTS(
SELECT * FROM artist_name_suggestions where original = artist_name
)
Thanks!
Firstly you can extract simple scopes:
scope :not_found, where(:artist_status => 'NOT_FOUND')
scope :blacklisted, where(:blacklisted => 1)
scope :extracted, where(:extracted => 0)
Then add a query method (assume artist_name is a column of scrape_datas):
def self.no_suggestions
scrape_datas = ScrapeData.arel_table
suggestions = ArtistNameSuggestion.arel_table
where(ArtistNameSuggestion.where(
suggestions[:original].eq(scrape_datas[:artist_name])
).exists.not)
end
Now you can do something like this:
ScrapeData.not_found.blacklisted.extracted.no_suggestions