How do i move a file located at the same place as my batch script to somewhere else? - batch-processing

I want my batch file to move a second file located at the same place.
I did the easiest method, which is move uninstall.bat "destination" but returns "System cannot find targeted file"
So I did this: move "%~dp0\uninstall.bat" "C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup", but it still can't find the file.

Related

How to copy a file without extension and at the end of the copy put it?

I am using teracopy to move some files. I would like to make a form in visual * .exe where you simply have two windows: one with the file's origin on the right, and another with the file's destination.
I need to copy the file without its extension, verify that the transfer occurred without issue, and then restore the original extension. For example:
Copy file.mov to // smb: Storage / Movies /
Remove the .mov extension
Copy the file to the storage location
Validate file size
If the file size at the destination matches the source, restore the .mov extension
If the file size doesn't match, delete the destination file and notify the user of the error.
The files I plan to copy are very large, and will take a good amount of time. I'm removing the extension so that users on the server will not accidentally try to access a file that isn't completely transferred yet - the idea is they see an "extensionless" file and know not to try and open it, whereas any files with extensions are certain to have copied over correctly.
I've tried using CMD and powershell, but I've only managed to copy the file or retry copying if the copy fails. I don't yet know how to remove the extension and restore it.
> ROBOCOPY /Mir <Source> <Target>
You can try this:
copy %UserProfile%\YourFile.* "Path to copy to"

Reopen DOC file in write mode, with macro inside it

I am using a macro template for particular DOC files only. It runs only for these files and, as I assume, it is treated as the DOC file itself.
All I want is to remove the file OR clear the contents of it, after the macro finishes. The initial file is read-only.
I have tried:
SavingAs in TEMP folder, change file attribute of initial file and then try to Kill it - no luck, it seems that initial file is still preloaded(?) and does not know that the read-only flag was removed. Error: Permision denied.
When I try to Close the initial document, I am closing also the macro itself...
So:
Is there any way to (from the macro inside the DOC file) :
Reopen the file in write-mode? (so I could clear the contents afterwards)
Remove the initial file? (after SaveAs so I actually will have a new file in write-mode and will be able to remove initial file)

I want to copy the file in sandbox without NSOpenPanel

I want to copy some files to specified folder by NSOpemPanel.
The source file is reading from XML and show to list in NSTable.
I can copy file by copyItemAtPath.
But now my app will turn to sandbox, then I can’t copy the file by copyItemAtURL.
How do I copy the file in sandbox mode?
I was looked over a lot of post. And I think the Security-scoped Bookmark may be a solution for this.
But I can’t create "Security-scoped Bookmark" from XML inside the path (the path was convert to NSURL ready).
I was setting to sandbox.entitlements but it's not clear this problem.
Is there any way for this?
Develop in macOS10.12 and Xcode8.3.3
Thanks
How do I copy the file in sandbox mode?
It is unclear what your current code is doing, but the rules under the sandbox are simple: To read or write a file located outside of an application's own container (which is hidden away under the Library folder) your application must either:
Use NSOpenPanel to obtain a URL from the user for the file path; or
Use NSOpenPanel to obtain a URL from the user for one of the ancestor folders of the file.
The second option gives access to a whole folder, including any sub-folders; i.e. the whole file/folder subtree rooted in the folder.
As you want to copy "some files" it sounds like asking the user for permission for the folder is appropriate. You can customise the NSOpenPanel to be a "request permission" dialog. If you are requesting a specific folder you can also have the dialog open in it's containing folder and only have the specific folder enabled for selection by the user.
Once you have the URL for the folder from NSOpenPanel you can create a security scoped bookmark for it and save that in your app's preferences or other configuration file (stored within the app's container). Doing this enables your app to regain access to the folder on subsequent executions without asking the user again.
If after investigating this issue and writing some code you hit an issue ask a new question, showing your code, and explaining the problem. Someone will undoubtedly help you with the next step.
HTH

Problems overwriting file in application folder

I have a file called PolicyLookup.sql that sits in my application's root folder. My app loads this file into a text box, so that users can edit it and overwrite the original file by pressing a save button. This all worked perfectly during test, however after deployment users are unable to save the file due to write issues within C:\Program Files.
Is there a way around this - or is there a better way to implement this type of thing? One solution that springs to mind for me is placing the contents of the PolicyLookup.sql file within a User Setting - however it intrinsically feels wrong to me to put the entire contents of a file within a settings variable.
Ordinary users do not have write permissions on %ProgramFiles%. If you need to save a configuration file then put it in a subfolder of %APPDATA% (which for me is C:\Users\Gord\AppData\Roaming) or some other place where a regular user is allowed to write.

NSIS doesn't backup all files

An NSIS installer creates a fairly large folder structure. When the installer starts, it checks the registry to see if there is a current version installed...
Then it asks if you want to make a backup of the current folder.
It works most of the time, but sometimes when it is backing up older versions, instead of copying over the entire directory, it only copies the icon.
!insertmacro un.MoveFolder "$INSTDIR" "${BACKUP_FOLDER}" "*.*"
Reference: http://nsis.sourceforge.net/MoveFileFolder
!insertmacro MoveFolder "$INSTDIR\[path\]source-folder[\]" "$INSTDIR\[path\]destination-folder[\]" "file-mask"
Afterwards, it moves on to the delete section...
Could it be that it doesn't have time to do it ? it starts the next process before finishing the move ?
What else could be going on so that it does not copy the entire folder ?
During the installer, I see
Create folder c:\backup_folder
Moving files: c:\current_folder\*.* to c:\backup_folder\
Delete file: c:\current_folder\file1.........
And at the end, backup_folder has only the icon (not all the files)
Edit: The solution - please see my post here NSIS difficulty moving folders - $INSTDIR is indeed a special folder so I had to move the uninstaller to a $TEMP folder.
Is there any reason why you cannot use the built-in CopyFiles command?
To debug this I would suggest that you add a DetailPrint near the top of the .MoveFolder_Locate_moveFile function. If you see all the file names go by then the problem is the move operation in that function, if not then the problem is in the ${Locate} macro used by this code.
Another alternative is to watch the filesystem operations with Process Monitor...