Hi,
I am trying to get into the scripting features of XY.
I used to do some powershell, but it had real trouble with [ and ] chars, plus others in filenames paths...
Also, I'd like to test XY scripting performance
My intent is to have a XY script that:
- From a selected directory.
- Find all sub-directories which contains a single item (file or directory) only (probably through listfolder or folderreport) *
- Display a "yes or no" dialogue box with full path and item name *
- If no selected, do nothing.
- If yes selected, move the item (file or directory) one level up, delete the now empty directory.
* These are the ones where I'd need to most help
Also let's say a folder contains a .jpg and the thumbs.db or desktop.ini
XY scripting seem to report 2 items. when for the user, there is really only the jpg file
can it ignore hidden/system files?
Finally, let's say I want to duplicate this Linux command in xyplorer
mv 20*/* .
Move all the files contained in folders starting with 20 to the current dir
is it even doable?
Thanks
XY scripting newbie questions
Re: XY scripting newbie questions
listfolder is non recursive so it doesn't make much sense to use that.Find all sub-directories which contains a single item (file or directory) only (probably through listfolder or folderreport) *
if a subdirectory contains only one folder (instead of a file), does it have to be empty to be moved one level up?
Within the script command? No. But you can always check the output of listfolder | folderreport command and if it contains any of these strings...can it ignore hidden/system files?
Sure. A folderreport with dirs and the recursive flag. A foreach loop to go through this output line by line and a regexmatch | replace to see if it starts with "20". True = move...is it even doable?
One of my scripts helped you out? Please donate via Paypal
Re: XY scripting newbie questions
hey HighEnd,
thanks for your answer.
>if a subdirectory contains only one folder (instead of a file), does it have to be empty to be moved one level up?
No, it's really just to "bubble up" items.
The case is a HUGE folder containing auto-extracted RARs
For example myArchive.rar:
Not to mix folders containing several files, the archive is extracted to /myArchive.
That doesn't make sense if there is a single file
so I'd be looking at moving /myArchive/myfile.pdf or /myArchive/myfolder up
but not /myArchive/{file1.xxx, file2.xxx}
>>is it even doable?
The reason I asked is that in DOS, I never figure out how to do it.
So a
moveto "d:\", "d:\20*\*.*";
wouldn't work? I find the inverted syntax quite dangerous too
maybe xy is not the right tool for this particular script ideas
thanks for your answer.
>if a subdirectory contains only one folder (instead of a file), does it have to be empty to be moved one level up?
No, it's really just to "bubble up" items.
The case is a HUGE folder containing auto-extracted RARs
For example myArchive.rar:
Not to mix folders containing several files, the archive is extracted to /myArchive.
That doesn't make sense if there is a single file
so I'd be looking at moving /myArchive/myfile.pdf or /myArchive/myfolder up
but not /myArchive/{file1.xxx, file2.xxx}
>>is it even doable?
The reason I asked is that in DOS, I never figure out how to do it.
So a
moveto "d:\", "d:\20*\*.*";
wouldn't work? I find the inverted syntax quite dangerous too
maybe xy is not the right tool for this particular script ideas
Re: XY scripting newbie questions
Again:so I'd be looking at moving /myArchive/myfile.pdf or /myArchive/myfolder up
It's clear that you want to move a file only if it's the only one in a folder
But for your example: What happens when
/myArchive/myfolder
is
a.) empty
has
b.) a subfolder / or file underneath it
Generally: Is it necessary to move up empty folders at all?
A few more examples for these cases would be nice.
Because you need a FOR loop to do that...The reason I asked is that in DOS, I never figure out how to do it.
NopeSo a
moveto "d:\", "d:\20*\*.*";
wouldn't work?
Huh? XY clearly lacks a few things (e.g. a better regex implementation) but what you want to do is absolutely possible...maybe xy is not the right tool for this particular script ideas
One of my scripts helped you out? Please donate via Paypal
Re: XY scripting newbie questions
Try this...
Test it only with unimportant data first!
1. Select the folder that should be processed
2. Run the script
Test it only with unimportant data first!
1. Select the folder that should be processed
2. Run the script
Code: Select all
if ((gettoken(get("SelectedItemsPathNames"), "count") == 1) && (exists("<curitem>") == 2)) {
setting "BackgroundFileOps", 0;
$delFolders = "";
$allFolders = folderreport("dirs", "r", "<curitem>", "r", , "<crlf>");
foreach($folder, $allFolders, "<crlf>") {
$stats = folderreport("dump", "r", $folder, , , "<crlf>");
$parent = regexreplace($folder, "(.*)(?=\\).*", "$1");
if (strpos($stats, "1 file, 0 folders") != -1) {
$file = listfolder($folder, "*", 1, "<crlf>");
backupto $parent, $file, 4, , , 0, , , 0;
$delFolders = $delFolders . $folder . "|";
} elseif (strpos($stats, "0 files, 1 folder") != -1) {
$subFolder = folderreport("items", "r", $folder, "r", , "<crlf>");
$subItems = gettoken($subFolder, "count", "<crlf>");
if ($subItems == 1) {
backupto $parent, $subFolder, 4, , , 0, , , 0;
$delFolders = $delFolders . $subFolder . "|";
}
}
}
delete 1, 1, $delFolders;
status "Finished Moving files | folders", "008000", "ready";
}One of my scripts helped you out? Please donate via Paypal
XYplorer Beta Club