D
dtown22
I am writing a small script which recursively goes down a dir
hierarchy, and when it reaches a set of files, it applies a 3rd party
application which modifies those files, and prepends the name with
"Mod-".
So for example, if i had a directory with only 1 file: C:\myDir
\myFile.txt, and I ran the app, I would end up with the following
files in c:\myDir
myFile.txt
Mod-myFile.txt
Basically, what i want to do is traverse down the hierarchy, when i
reach a set of files, call the app on that directory, then delete the
original, and rename the new file so that the "Mod-" is removed.
Unfortunately, the Find function doesnt see the newly created file,
and thus i cant delete & rename. My code looks something like this:
Find.find(startingDir) do |path|
if File.directory?(path)
next
else
system("myapp #{path}")
puts path
if File.basename(path) =~ /^Mod-/
if File.exists?(path.sub('Mod-', ''))
File.delete(path.sub('Mod-', ''))
end
File.rename(path, path.sub('Mod-', ''))
end
end
end
I was wondering if there was a way to reset the path one level up
(i.e. where "puts path" is above), that way the current directory
would be refreshed, and the new files would be recognized.
thanks!
hierarchy, and when it reaches a set of files, it applies a 3rd party
application which modifies those files, and prepends the name with
"Mod-".
So for example, if i had a directory with only 1 file: C:\myDir
\myFile.txt, and I ran the app, I would end up with the following
files in c:\myDir
myFile.txt
Mod-myFile.txt
Basically, what i want to do is traverse down the hierarchy, when i
reach a set of files, call the app on that directory, then delete the
original, and rename the new file so that the "Mod-" is removed.
Unfortunately, the Find function doesnt see the newly created file,
and thus i cant delete & rename. My code looks something like this:
Find.find(startingDir) do |path|
if File.directory?(path)
next
else
system("myapp #{path}")
puts path
if File.basename(path) =~ /^Mod-/
if File.exists?(path.sub('Mod-', ''))
File.delete(path.sub('Mod-', ''))
end
File.rename(path, path.sub('Mod-', ''))
end
end
end
I was wondering if there was a way to reset the path one level up
(i.e. where "puts path" is above), that way the current directory
would be refreshed, and the new files would be recognized.
thanks!