move a file to a parent folder
Moderators: fgagnon, nikos, Site Mods
move a file to a parent folder
I want to move up the current file to the parent folder by pressing the button once.by usercommand or button
> move "$N" "$P"
This is bad,isn't it ?
sorry for my rudimentary question,often
Though reply of short sentence , It works for me.
thank you
> move "$N" "$P"
This is bad,isn't it ?
sorry for my rudimentary question,often
Though reply of short sentence , It works for me.
thank you
this command would not work as $P is the same folder
you can try this (observe the two dots .. at the end)
you can try this (observe the two dots .. at the end)
Code: Select all
$ move "$F" ..
Something similar. I use following autohotkey script to flatten current folder.
All the files from child folders are physically moved to the current folder (as long as there are no duplicates) and all the empty child folders are then deleted.
All the files from child folders are physically moved to the current folder (as long as there are no duplicates) and all the empty child folders are then deleted.
Code: Select all
if %1%
{
currentFolder = %1%
MsgBox, 4, , Do you want to flatten folder %currentFolder%`n`nContinue?
IfMsgBox, No
return
}
else
{
return
}
Loop, %currentFolder%\*.*, , 1 ; Recurse into subfolders.
{
; Skip files in current folder
If A_LoopFileDir = %currentFolder%
continue
FileMove, %A_LoopFileFullPath%, %currentFolder%, 0
}
;Delete Empty folders
; Get all the folders under current directory
Loop, %currentFolder%\*.*,2
{
FolderSize = 0
Loop, %A_LoopFileFullPath%\*.*, , 1
FolderSize += %A_LoopFileSize%
if FolderSize = 0
{
;MsgBox Deleting folder %A_LoopFileFullPath% with size %FolderSize%
FileRemoveDir, %A_LoopFileFullPath%
}
}
Help! I'm an AI running around in someone's universe simulator.
Hah, that's an interesting approach - I assume its primary purpose is to collapse redundancies? Wait, scratch that - if all the contents are moved without retaining the containing folder structure it's kind of a big single-level-flattening-merge-type-o-thing then, yeah? I presume it has a custom purpose? (Bloody AHK syntax is weird - I can't tell if it recurses in or not - in the attempt to be more beginner-friendly , AHK actually seems to alienate others by being too general. The lord loves a bit of obfuscation in his devilish-details - somehow it's more comforting.)
I download lot of stuff online and in many cases the downloaded folders have redundant child folders containing one or two files. I use this script to move all the children to the parent folder. Earlier I used the X2 flatten command and would then cut & paste files from the scrap pane. With this script its just a single click toolbar operation.Kilmatead wrote:all the contents are moved without retaining the containing folder structure it's kind of a big single-level-flattening-merge-type-o-thing then, yeah? I presume it has a custom purpose?
Kilmatead wrote: Bloody AHK syntax is weird - I can't tell if it recurses in or not - in the attempt to be more beginner-friendly , AHK actually seems to alienate others by being too general. Very Happy The lord loves a bit of obfuscation in his devilish-details - somehow it's more comforting.
It took me some time to wrap my head around AutoHotKey syntax when I first moved from vbscript. I preferred AutoIt3 initially as its syntax was quite close to vbs syntax.
Over the time I have started to like ahk as it has very powerful set of windows automation APIs. Its command syntax is often quite compact. In this case I am able to achieve recursive behavior without writing recursive code . Thisis how file looping in AHK works.
Help! I'm an AI running around in someone's universe simulator.
thanks
Thank you for many reply.
Is the most standard answer the following one?
>$ move "$F" ..
Though I am selfish ,It might not be avoided that the console box come out .
It is terrible and obstructive.
It can't be helped in this software ?
In addition, I meets the bug that the file name is changed to "exit...". It might be because the file names are two bytes.
I gives it up.
I also am using AHK regularly. Though I am a beginner. If possible, I want to move only one file.
Thank you. Everyone
Is the most standard answer the following one?
>$ move "$F" ..
Though I am selfish ,It might not be avoided that the console box come out .
It is terrible and obstructive.
It can't be helped in this software ?
In addition, I meets the bug that the file name is changed to "exit...". It might be because the file names are two bytes.
I gives it up.
I also am using AHK regularly. Though I am a beginner. If possible, I want to move only one file.
Thank you. Everyone
Do you happen to have a "compiled" version of the script you would be willing to share?snakebyte wrote:Something similar. I use following autohotkey script to flatten current folder.
____________________________________________________________
PJ in (I guess noone really cares about the posts I made this week) FL
Here you go.
Usage:
Please exercise caution while executing this script as its action cannot be undone. Test it first on some temp folder with test files before going wild with it.
Usage:
Code: Select all
> FlattenFolder.exe "$P"
Help! I'm an AI running around in someone's universe simulator.
-
- Silver Member
- Posts: 281
- Joined: 2006 Dec 29, 12:56
- Location: Utrecht, NL
Can I add one to the competition? I use this one for quite some time already, so it has been through some testing (the usual precautions and disclaimers of course still holds true ). Just like Snakebyte's script, as I understood it, it 'elevates' the contents of a folder, but mine does not flatten the content.
So you select a folder (not a file) in the current folder and run the script, the content of the selected folder will go into the current folder, and the previously selected folder will be emptied and removed.
Should you have any conflicts by doing this (the selected folder has any sibling files or folders with the same name as any of the child-files or folders), then the whole thing is abandoned without any harm done.
Put the code below in an empty plain text file, save it with the extension '.vbs', and create a custom user command with the descriptionContent of the vbs-file:
So you select a folder (not a file) in the current folder and run the script, the content of the selected folder will go into the current folder, and the previously selected folder will be emptied and removed.
Should you have any conflicts by doing this (the selected folder has any sibling files or folders with the same name as any of the child-files or folders), then the whole thing is abandoned without any harm done.
Put the code below in an empty plain text file, save it with the extension '.vbs', and create a custom user command with the description
Code: Select all
>> wscript "[path-to-the-vbs-file]" "$F"
Code: Select all
Dim filesys, selectedfolder
Set filesys=CreateObject("Scripting.FileSystemObject")
If selecteditemcheck (WScript.Arguments.Item(0), filesys)=1 Then
Set selectedfolder = filesys.GetFolder(WScript.Arguments.Item(0))
If levelconflict (selectedfolder, filesys) = 0 Then
movestructure (selectedfolder)
selectedfolder.Delete
ElseIf levelconflict (selectedfolder, filesys) = 1 Then
selectedfolder.Name = filesys.GetTempName
movestructure (selectedfolder)
selectedfolder.Delete
Else msgbox "Can not finish command. At least one file/folder inside the selected folder carries the same name as a file/folder next to the selected folder.", VBOKOnly, "Error"
End If
ElseIf selecteditemcheck (WScript.Arguments.Item(0), filesys)=2 Then
msgbox "This function will not work on a selected file: " & WScript.Arguments.Item(0), VBOKOnly, "Error"
End If
Function movestructure (folderobject)
Set foldercontentfolders = folderobject.Subfolders
Set foldercontentfiles = folderobject.Files
For Each i In foldercontentfolders
i.Move (i.ParentFolder.ParentFolder & "\")
Next
For Each i In foldercontentfiles
i.Move (folderobject.ParentFolder & "\")
Next
End Function
Function levelconflict (folderobject, filesystemobject)
levelconflict = 0
If filesystemobject.FolderExists(folderobject & "\" & folderobject.Name) = True Then
levelconflict = 1
End If
For Each i In folderobject.SubFolders
If filesystemobject.FolderExists(folderobject.ParentFolder & "\" & i.Name) = True And folderobject.ParentFolder & "\" & i.Name <> folderobject Then
levelconflict = 2
End If
Next
For Each i In folderobject.Files
If filesystemobject.FileExists(folderobject.ParentFolder & "\" & i.Name) = True Then
levelconflict = 2
End If
Next
End Function
Function selecteditemcheck (path, filesystemobject)
If filesystemobject.FolderExists(path)=True Then
selecteditemcheck = 1
ElseIf filesystemobject.FileExists(path)=True Then
selecteditemcheck = 2
Else selecteditemcheck = 0
End If
End Function
-
- Gold Member
- Posts: 428
- Joined: 2011 Jan 23, 18:58
- Location: Sydney AU
I must be missing something
50 odd lines of VB to do - ctrl/x, backspace, ctrl/v - seems extravagant to me.
I guess I'm still in the century before last, seeing everything through the prism of a Friden paper tape reader/writer
:sigh:
50 odd lines of VB to do - ctrl/x, backspace, ctrl/v - seems extravagant to me.
I guess I'm still in the century before last, seeing everything through the prism of a Friden paper tape reader/writer
:sigh:
Windows 10 Pro (64 bit) version 1809 - Xplorer2 version: Pro 2.5.0.4 [Unicode] x64 2014-06-21
-
- Silver Member
- Posts: 281
- Joined: 2006 Dec 29, 12:56
- Location: Utrecht, NL
It is extravagant, true. It seemed a simple thing to do, when I started writing the script, but it turned out that it had to cover for different scenarios.
Anyway, you can run scripts like these on a host of folders (also in the scrap container), whereas (ctrlA-) ctrlX-backspace-ctrlV only works on one. At the time, I had to do that for many, many folders, that's how I got bored so much
Anyway, you can run scripts like these on a host of folders (also in the scrap container), whereas (ctrlA-) ctrlX-backspace-ctrlV only works on one. At the time, I had to do that for many, many folders, that's how I got bored so much