file-copying

Copy a file with its original permissions

风格不统一 提交于 2019-11-29 04:36:53
When using the File.Copy() method the file is copied to its new directory however it loses its original permissions. Is there a way to copy a file so that it doesn't lose the permissions? Alex Mendez I believe you can do something like this: const string sourcePath = @"c:\test.txt"; const string destinationPath = @"c:\test2.txt" File.Copy(sourcePath, destinationPath); FileInfo sourceFileInfo = new FileInfo(sourcePath); FileInfo destinationFileInfo = new FileInfo(destinationPath); FileSecurity sourceFileSecurity = sourceFileInfo.GetAccessControl(); sourceFileSecurity.SetAccessRuleProtection

Python: How to Copy Files Fast [duplicate]

∥☆過路亽.° 提交于 2019-11-28 23:03:45
问题 This question already has an answer here: How do I copy a file in Python? 16 answers It takes at least 3 times longer to copy files with shutil.copyfile() versus to a regular right-click-copy > right-click-paste using Windows File Explorer or Mac's Finder. Is there any faster alternative to shutil.copyfile() in Python? What could be done to speed up a file copying process? (The files destination is on the network drive... if it makes any difference...). EDITED LATER: Here is what I have ended

Copy file from setup location to another location in wix on install

∥☆過路亽.° 提交于 2019-11-28 12:10:43
I have created an msi setup file which includes some files in a "Sample" folder which should be copied to a temp folder. Anybody suggest how to do this? Something like this: <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder"> <Directory Id="MyVendor" Name="MyVendor"> <Directory Id="INSTALLDIR" Name="MyDir"> <Component Id="MyFileId" Guid="...G1..."> <File Id="MyFileId" Name="MyFile" Source="...blabla...\MyFile" KeyPath="yes" > </File> </Component> <DirectoryRef Id="TARGETDIR"> <Component Id="MyFileCopyId" Guid="...G2..."> <RemoveFile Id="MyFileRemoveId" Name="MyFile"

How do I copy a remote image in python?

此生再无相见时 提交于 2019-11-28 06:00:37
I need to copy a remote image (for example http://example.com/image.jpg ) to my server. Is this possible? How do you verify that this is indeed an image? Nadia Alramli To download: import urllib2 img = urllib2.urlopen("http://example.com/image.jpg").read() To verify can use PIL import StringIO from PIL import Image try: im = Image.open(StringIO.StringIO(img)) im.verify() except Exception, e: # The image is not valid If you just want to verify this is an image even if the image data is not valid: You can use imghdr import imghdr imghdr.what('ignore', img) The method checks the headers and

How to copy file from smb share to local drive using jcifs in Java?

强颜欢笑 提交于 2019-11-28 01:14:00
Could anybody help me to copy file from shared folder to local drive? My code is: import jcifs.smb.NtlmPasswordAuthentication; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileInputStream; import jcifs.smb.SmbFileOutputStream;; public class smb { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub String urlToBackUpFile = "smb://ip/backup$/test.txt"; System.out.println("smb folder of source file" + urlToBackUpFile); NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "login", "pass");

Permission denied on CopyFile in VBS

白昼怎懂夜的黑 提交于 2019-11-27 23:27:33
I'm trying to automate pushing a file into my users' home directories, but am stuck on a "Permission Denied" error — is thrown on line 6 here, with the CopyFile call. There are other parts of the script (not shown) that create and copy folder contents using the same source and destination directories, and they work perfectly. It's only when I use CopyFile that it fails. dim fso set fso = CreateObject("Scripting.FileSystemObject") if not fso.FileExists("H:\Minecraft\.minecraft\options.txt") then fso.CopyFile "C:\Minecraft\options.txt", "H:\Minecraft\.minecraft\" end if set fso = nothing H: is a

Copy a file with its original permissions

心已入冬 提交于 2019-11-27 18:34:49
问题 When using the File.Copy() method the file is copied to its new directory however it loses its original permissions. Is there a way to copy a file so that it doesn't lose the permissions? 回答1: I believe you can do something like this: const string sourcePath = @"c:\test.txt"; const string destinationPath = @"c:\test2.txt" File.Copy(sourcePath, destinationPath); FileInfo sourceFileInfo = new FileInfo(sourcePath); FileInfo destinationFileInfo = new FileInfo(destinationPath); FileSecurity

Moving files between folders

爱⌒轻易说出口 提交于 2019-11-27 12:36:31
I want to copy/paste a file from one folder to another folder in windows using R, but it's not working. My code: > file.rename(from="C:/Users/msc2/Desktop/rabata.txt",to="C:/Users/msc2/Desktop/Halwa/BADMASHI/SCOP/rabata.tx") [1] FALSE If you wanted a file.rename() -like function that would also create any directories needed to carry out the rename, you could try something like this: my.file.rename <- function(from, to) { todir <- dirname(to) if (!isTRUE(file.info(todir)$isdir)) dir.create(todir, recursive=TRUE) file.rename(from = from, to = to) } my.file.rename(from = "C:/Users/msc2/Desktop

Copy file from setup location to another location in wix on install

时间秒杀一切 提交于 2019-11-27 06:55:10
问题 I have created an msi setup file which includes some files in a "Sample" folder which should be copied to a temp folder. Anybody suggest how to do this? 回答1: Something like this: <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder"> <Directory Id="MyVendor" Name="MyVendor"> <Directory Id="INSTALLDIR" Name="MyDir"> <Component Id="MyFileId" Guid="...G1..."> <File Id="MyFileId" Name="MyFile" Source="...blabla...\MyFile" KeyPath="yes" > </File> </Component> <DirectoryRef

Copying raw file into SDCard?

随声附和 提交于 2019-11-27 02:08:11
I've some audio files in my res/raw folder. For some reasons, i want to copy this files to my SDCard When, my application starts. How can i done this? Anyone guide me? Nikolay Elenkov Read from the resource, write to a file on the SD card: InputStream in = getResources().openRawResource(R.raw.myresource); FileOutputStream out = new FileOutputStream(somePathOnSdCard); byte[] buff = new byte[1024]; int read = 0; try { while ((read = in.read(buff)) > 0) { out.write(buff, 0, read); } } finally { in.close(); out.close(); } Copy file from raw to External Storage: This is a method that i use to do