Page 1 of 1

Help for writing list of the files to 2 files

Posted: 19 Jul 2010 02:19
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.

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

Posted: 19 Jul 2010 04:26
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 _

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

Posted: 19 Jul 2010 10:04
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.

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

Posted: 19 Jul 2010 13:32
by lazydba
Thanks so much. It worked like a charm. :D :D :D

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

Posted: 19 Jul 2010 14:23
by admin
@Stefan: I don't think "sel +1;" changed its behavior.

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

Posted: 19 Jul 2010 15:04
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

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

Posted: 19 Jul 2010 16:11
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.

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

Posted: 19 Jul 2010 16:23
by lazydba
Yes. That is what I wanted. Worked perfect. Thanks so much.