Help for writing list of the files to 2 files

Discuss and share scripts and script files...
Post Reply
lazydba
Posts: 4
Joined: 19 Jul 2010 02:07

Help for writing list of the files to 2 files

Post by lazydba »

I have bunch of folders in the current directory. Each folder will have bunch of files ( no sub folders though )
First I need to replace all the spaces in the folder names with an underscore then I need to crate 2 txt files.
All the file names in folder X should go into first text file and files in all other folders will to into second file.

folder 1
folder 2
folder 3
folder X
folder 4

Can this be done using script ? Thanks in advance.

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Help for writing list of the files to 2 files

Post by j_c_hallgren »

Hi and welcome to the XY forums!
lazydba wrote:First I need to replace all the spaces in the folder names with an underscore
I'm not a script'r but can tell you that this particular function can easily be done via File>Rename Special>Spaces to _
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Help for writing list of the files to 2 files

Post by Stefan »

Hi and welcome lazydba.

Please see if you can do something with this script.
See the wiki how to use an script: http://88.191.26.34/XYwiki/index.php/Scripting

Code: Select all

"Rename Special: Spaces to _"
	//Just use the build-in command: "File>Rename Special>Spaces to _"
	//Select items to rename first on your own.
	#129;

"List files to text file"
	//Select the first folder in question on your own first.
	$StartFolder = "<curpath>";
	$XFolder ="";
	$OtherFolders = "";

	while(1){
	   $IsFolder = report ("{Dir Yes|No|Drive}",1);
	   IF ("$IsFolder" == "Yes"){
	      $ActualFolder = "<curname>";
	      $curfolder = "<curitem>";
	      goto $curfolder;
	      IF ("<curname>"=="X"){
	         $XFolder = $XFolder$curfolder<crlf> . Report("{Name}<crlf>") . <crlf>;
	      }else{
	         $OtherFolders = $OtherFolders$curfolder<crlf> . Report("{Name}<crlf>") . <crlf>;
	      }
	   goto $StartFolder;
	   sel "[$ActualFolder]";
	   sel +1;
	   }else{
		   msg "No more folders. See output files.";
		   
		   //just sgow an messages box:
		   //If (strlen($XFolder) > 0) {text $XFolder;}
		   //If (strlen($OtherFolders) > 0) {text $OtherFolders;}
		   
		   //write info to file:
		   //writefile(filename, data, [on_exist], [mode])
		   If (strlen($XFolder) > 0) {writefile("C:\Temp\XFolders.txt", $XFolders);}
		   If (strlen($OtherFolders) > 0) {writefile("C:\Temp\OtherFolders.txt", $OtherFolders);}
		   break;
	   }
	}


Note:
"sel +1;" didn't selected just the next item anymore for me (but the second in list), i think it has done in past?
So i used "sel "[$ActualFolder]";" first here.

lazydba
Posts: 4
Joined: 19 Jul 2010 02:07

Re: Help for writing list of the files to 2 files

Post by lazydba »

Thanks so much. It worked like a charm. :D :D :D

admin
Site Admin
Posts: 60635
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Help for writing list of the files to 2 files

Post by admin »

@Stefan: I don't think "sel +1;" changed its behavior.

lazydba
Posts: 4
Joined: 19 Jul 2010 02:07

Re: Help for writing list of the files to 2 files

Post by lazydba »

Right now it is forcing me to select the first folder in the list. Is there a way to avoid that. No beggie, sometimes I might forget to select it. thx

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Help for writing list of the files to 2 files

Post by Stefan »

lazydba wrote:Right now it is forcing me to select the first folder in the list. Is there a way to avoid that. No beggie, sometimes I might forget to select it. thx
I don't understand. What is the part you want?

Should the script select the first folder for you?
Then just write an
sel 1;
right under
//Select the first folder in question on your own first.

lazydba
Posts: 4
Joined: 19 Jul 2010 02:07

Re: Help for writing list of the files to 2 files

Post by lazydba »

Yes. That is what I wanted. Worked perfect. Thanks so much.

Post Reply