c# - Copy all contents of a directory and change names of the existing contents -


There is a start here I am trying to copy all the contents from one folder to another, suppose the initial folder is called inputDir , and the file I copy is called outputDir thing is, some files already in outputdir , And all of them have been named like files in inputDir . This looks like this: - inputDir * hit0.png * hit100.png * hit300.png - outputDir * hit0.png * hit100.png * hit300.png

What I am trying to do is to designate all the files inside outputDir so that all the characters are 'bak' at the end of their 'name' And then copy all the files from inputDir to outputDir before their extension. In short, I want to look it like this:

  - inputDir * hit0.png * hit100.png * hit300.png - outputDir * hit0.png * hit0bak.png * hit100.png * Hit00bak.png * hit300.png * hit300bak.png   

So far, I've tried to do this separately for each file, and it works fine; However, to write a lot of code, 20 more files are monotonous, so I'd love to know that there is a fast way to do this in C # (yes, I need it in C #, I wrote in the program More than that, but I've already covered everything). Thank you in advance for any help.

This is what I have tried so far:

  if (file.Exists (outputDir + "\\" + "hit0 PNG")) (file.main Output DIR + "\\" + "Hit -0.png", Output DIR + "\\" + "Hit-02.Connect"); File Next (Output DIR + "\\" + "Hit 100.png "Output dir +" \\ "+" hit 100 bak.png "); file. Forward (outputdir +" \\ "+" hit 300.png ", outputdear +" \\ "+" hit 300bak.png "); } File Copy (Input + + "\\" + "hit0.png", outputDir + "\\" + "hit0.png"); File Copy (InputDir + "\\" + "Hit 100.png" , Output DIR + "\" "+" hit100.png "); File Copy (InputIir +" \\ "+" Hit 300.png ", output dir +" \\ "+" hit 100.png ");    

source = path =" c: \ source \ path "; var destPath = @" c: \ dest \ path "; var sourceDirInfo = new System.IO.DirectoryInfo (sourcePath); foreach (source {Source} firefind (if.exists (Path.Combine (destPath, sourceFileInfo.Name)) in source.info.GetFiles ()) {var bakName = sourceFileInfo.Name.Replace (".", "Bak."); File. Forward (path. Cobain (destipath, sourcefile info name), path. Combine (destpath, bunked)); } File.copy (path.combine (source path, sourcefileInfo .name), path. Cobain (destepath, sourcefileinfooinname.)); }

(Warning - works for '.' In the file names only for one)

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -