This is what I am after.
- File or folder is dragged and dropped on the application shortcut
- User is prompted for an entry
- The dropped file or folder is renamed, with the text returned from the prompt as a file prefix, followed by a separator character (hyphen, underscore, space - any of those)
- Renamed file or folder is copied to a specific destination folder, which is always the same folder
If that is impossible, this is another option:
- Application is launched (no drag and drop)
- User is prompted to browse to file or folder to select it
- User is then prompted for text entry (note: steps 2 and 3 can be reversed if it makes things easier)
- File or folder selected in step 2 is renamed with the text returned from 3 as a prefix, followed by a separator character
- Renamed file or folder is copied to a specific destination folder, which is always the same folder
I have to say, the destination folder is a hot folder. So best to do the renaming before the copy, if possible.
I have done this in Mac environment using AppleScript. I am not sure about how to approach in Windows. BAT file? Javascript? At this point all I have done is write a javascript which prompts for text and returns text string as an alert, with returned text of prompt in the string in a Mac environment:
var app = Application("Finder")
app.includeStandardAdditions = true
var response = app.displayDialog("ENTER JOB NO",{
defaultAnswer: "",
buttons: ["Cancel","Continue"],
defaultButton: "Continue"
})
app.displayDialog("Hello! Your job number is " (response.textReturned))
Different from Windows, and I am not as proficient in Windows, bat files, or javascript either. Also I'm not sure if javascript is the best approach for what I want.
CodePudding user response:
I wrote a .bat:
@echo off
echo The file you dropped is: %1
set /p "jobno=Enter Job No: "
Dropped file or folder is identified as a path, and then it prompts for entry.
Not much of a start, but something. One problem I see is extracting the file name from the path. The job number would need to be inserted after the final "/"
Another possibility:
- File or folder is dropped on bat
- User is prompted for job number
- New folder created on desktop, with the job number being the name of the folder
- Original dropped file or folder is moved into this new folder
- The job number folder containing the original drop is then copied to the final destination
This would work and I get around renaming.
Is Powershell a better option for this, instead of a batch file? Sorry for my lack of knowledge here.
CodePudding user response:
I wrote another bat
@echo off
echo The file you dropped is: %1
set /p "jobno=Enter Job No: "
set varfile=%1
xcopy %varfile% "C:\Users\me\Desktop\%jobno%\"/s
This seems to work. Strange result if the dropped is a folder. It actually extracts all contents from the original folder and copies them to the new folder named with the job number.
The /s ensures that subfolders are also copied, if they exist.
I am still wondering if Powershell might be a better solution. I get the impression that it is far superior to bat files. Maybe the bat files are outdated, like AppleScript on a Mac.