spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Issue with program for renaming files


My guess is that it not only skips some numbers, but that it deletes some files actually! When renaming the files, you might end up overwriting some already existing files. Take the following example: You have 3 files: 0.jpg, 1.jpg, 2.jpg. They should be renamed as follows (a possible result of your shuffling):

0.jpg -> 1.jpg
1.jpg -> 2.jpg
2.jpg -> 0.jpg

This would work if all the files would be renamed at the same time. But if they are renamed sequentually, the first renaming (0.jpg -> 1.jpg) will overwrite the "old" 1.jpg. When the "old" 1.jpg should be renamed, it's actually the new 1.jpg (=old 0.jpg) being renamed to 2.jpg, overwriting the "old" 2.jpg. And then, that file get's renamed again to 0.jpg. So, you'll end up only with 0.jpg (which in this case is actually the same as the original 0.jpg), but you've overwritten and thus lost the others.

Depending on your shuffling, you might end up overwriting only some of the files, and thus see some numbers skipped.

How to solve it? 2 Variants: 1) move the files to a new directory, and then in the end delete the old directory (it should be empty now, as all files have been moved) and rename the new directory to the name of the original directory. 2) rename the files first to include some prefix, e.g. "tmp_" + j + "." + extension, and after all files have been renamed, rename the files again to remove the prefix.

Both variants make sure that no file is accidentially overwritten.


Categories : Java

Related to : Issue with program for renaming files
JDK 1.7 not shown in Program Files folder
Try "javac -version" instead of "java -version" to confirm JDK installed version It seems that you have a 1.7 Java Runtime but only 1.6 SDK installed. Just get the correct SDK installer from java.com.

Categories : Java
Java MapReduce program to work on PDF files
The problem is you are using the wrong api(old org.apache.hadoop.mapred.*api) Please use the new API (org.apache.hadoop.mapreduce.*) org.apache.hadoop.mapreduce.lib.input.FileInputFormat; org.apache.hadoop.mapreduce.RecordReader; The SO answer you following using this new API. In new API RecordReader is class not interface UPDATE mapred vs mapreduce API

Categories : Java
Timing issue? Program runs fine in Visual Studio but not standalone
You're likely suffering from lack of synchronisation between the thread that is collecting the data (and building the list of buffers) and the thread that the application uses to access (and presumably remove) the buffers. You likely need to include some locking around access to the buffer list. It seems that you have an "active" buffer which only the data reader thread can write into (buffer) an

Categories : C#
Progress bar not showing up in copy files from one drive to another program in java
I found an answer and modified a bit to suit to my needs. Thanks, Following is the link : Need to have JProgress bar to measure progress when copying directories and files

Categories : Java
Performance issue with too many css files in rails 4 app?
Check this article out on bundling: http://www.asp.net/mvc/overview/performance/bundling-and-minification. Even though the article is about bundling in .NET, the browser/performance related concerns are applicable. In short, browsers can only get 6 resource files at a time so, even though you have your stylesheets minified making the file size smaller, performance will be affected because of the

Categories : CSS
Recently Add
Redirecting the output directory of 'mvn package' or 'mvn compile' command
No suitable constructor found for ProductoExtranjero
java Composite design pattern(Directory &File)
Java JTree's ui refresh after removing node from parent
First REST Spring application
How to cancel Indexing of a Solr document using Update Request Processor
PowerMock - Mock a Singleton with a Private Constructor
Calling a Postgres stored function SQL error
Where to store Morphlines Java custom command class?
Generic repository using map
How can I scroll a ScrolledComposited in Eclipse SWT Design view?
2 Frames/layout in 1 Activity
Writing a switch differently
Next button opens another activity when its reaches the array limit
Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?
Why my jdk can't work,and before the java_home, there is a space that is not from me
How to add List of objects in a Map
How to make notepad++ function like regular notepad in cmd?
Cell renderer and the lost focus
how can I implement iterable for LinkedList>
Disable Androids image-crunch in eclipse (run as) builds
java 8 lambda myMap.stream().count() != myMap.size() after merging myMap
Issue with Calendar calculation that spans 2 calendar years
JSF 2.0 Spring bean injection
Java Regex ReplaceAll with grouping
Getting any word and last word using sed
Clicking on link on JEditorPane throws IOException
printing out difference of two arrays
Spring Bean Alias in JavaConfig
Using Factory Method to Create Generics
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.